leolaish commited on
Commit
c573b08
·
verified ·
1 Parent(s): 7d4a022

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -27
app.py CHANGED
@@ -20,6 +20,8 @@ from sympy.parsing.latex import parse_latex
20
  import base64
21
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
22
  from transformers import AutoTokenizer, AutoModelForPreTraining
 
 
23
 
24
  #client = OpenAI(
25
  # base_url=os.environ.get("SERVER_URL"),
@@ -534,36 +536,21 @@ def parse_data_chunk(data_chunk):
534
  data_chunk = data_chunk.text
535
  chunks = data_chunk.split("data:")
536
 
537
- def generate(message, temperature):
538
  """
539
- Generates a chat completion response by streaming data from the client chat model.
540
-
541
- This function streams the response from the client chat model and yields the content
542
- of the response chunk by chunk. If an error occurs, it yields the error message.
543
-
544
  Parameters:
545
- message (str): The input message to be sent to the chat model.
546
- temperature (float): The sampling temperature to use. Higher values mean the model will take more risks.
547
-
548
- Yields:
549
- tuple: A tuple containing the content of the response and a boolean flag indicating if an error occurred.
550
- If no error occurred, the boolean flag will be False and the content will be the response text.
551
- If an error occurred, the boolean flag will be True and the content will be the error message.
552
  """
553
- response = client.chat.completions.create(
554
- model="H4/zephyr-7b-beta",
555
- messages=message,
556
- stream=True,
557
- max_tokens=1024,
558
- stop=["output\n"],
559
- temperature=temperature,
560
- #timeout=30,
561
- )
562
-
563
- #response = stream.text
564
-
565
- # The reason why the library method is not used here is that if an error occurs,
566
- # the returned data will not be a stream, and using the official library will result in an error.
567
  for chunk in response:
568
  chunk = chunk.decode("utf-8") if isinstance(chunk, bytes) else chunk
569
  data_chunks = parse_data_chunk(chunk)
 
20
  import base64
21
  from transformers import AutoModelForSequenceClassification, AutoTokenizer
22
  from transformers import AutoTokenizer, AutoModelForPreTraining
23
+ from langchain_community.llms.manifest import ManifestWrapper
24
+ from manifest import Manifest
25
 
26
  #client = OpenAI(
27
  # base_url=os.environ.get("SERVER_URL"),
 
536
  data_chunk = data_chunk.text
537
  chunks = data_chunk.split("data:")
538
 
539
+ def parse_data_chunk(data_chunk):
540
  """
541
+ Parse a given data chunk string into a list of individual data entries.
542
+ The function splits the input string by the delimiter "data:" and removes any
543
+ leading or trailing whitespace from each resulting chunk. Empty chunks are
544
+ filtered out from the final list.
 
545
  Parameters:
546
+ data_chunk (str): The input string containing data chunks separated by "data:".
547
+ Returns:
548
+ list: A list of individual data entries with whitespace stripped.
 
 
 
 
549
  """
550
+ if isinstance(data_chunk, InferenceClient.ChatCompletionStreamOutput): # Update this line if you're using a different client class
551
+ data_chunk = data_chunk.text
552
+ chunks = data_chunk.split("data:")
553
+
 
 
 
 
 
 
 
 
 
 
554
  for chunk in response:
555
  chunk = chunk.decode("utf-8") if isinstance(chunk, bytes) else chunk
556
  data_chunks = parse_data_chunk(chunk)