Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,9 +38,16 @@ def respond(
|
|
| 38 |
):
|
| 39 |
token = message.choices[0].delta.content
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
response += token
|
| 42 |
yield response
|
| 43 |
-
except
|
| 44 |
yield f"Error: {e}"
|
| 45 |
|
| 46 |
"""
|
|
|
|
| 38 |
):
|
| 39 |
token = message.choices[0].delta.content
|
| 40 |
|
| 41 |
+
# Check if the token is a valid JSON string
|
| 42 |
+
try:
|
| 43 |
+
json.loads(token)
|
| 44 |
+
except json.JSONDecodeError:
|
| 45 |
+
yield f"Error: Invalid JSON response - {token}"
|
| 46 |
+
break
|
| 47 |
+
|
| 48 |
response += token
|
| 49 |
yield response
|
| 50 |
+
except Exception as e:
|
| 51 |
yield f"Error: {e}"
|
| 52 |
|
| 53 |
"""
|