Update app.py
Browse files
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
|
| 538 |
"""
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
Parameters:
|
| 545 |
-
|
| 546 |
-
|
| 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 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 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)
|