Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -32,17 +32,27 @@ def respond(
|
|
32 |
|
33 |
response = ""
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
response += token
|
45 |
-
yield response
|
46 |
|
47 |
"""
|
48 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
32 |
|
33 |
response = ""
|
34 |
|
35 |
+
try:
|
36 |
+
for message in client.chat_completion(
|
37 |
+
messages,
|
38 |
+
max_tokens=max_tokens,
|
39 |
+
stream=True,
|
40 |
+
temperature=temperature,
|
41 |
+
top_p=top_p,
|
42 |
+
):
|
43 |
+
payload = message.choices[0].delta.content
|
44 |
+
# Attempt to decode the payload, but handle JSON errors gracefully
|
45 |
+
try:
|
46 |
+
token = json.loads(payload.lstrip("data:").rstrip("/n"))["content"]
|
47 |
+
response += token
|
48 |
+
yield response
|
49 |
+
except json.JSONDecodeError as e:
|
50 |
+
print(f"JSON decoding error: {e} - payload: {payload}")
|
51 |
+
continue # Skip malformed payloads and continue
|
52 |
+
except Exception as e:
|
53 |
+
print(f"Error in chat completion: {e}")
|
54 |
+
yield "Error processing response from the model."
|
55 |
|
|
|
|
|
56 |
|
57 |
"""
|
58 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|