Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -110,17 +110,17 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 110 |
if line.strip() == "[DONE]":
|
| 111 |
break
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
|
| 126 |
|
|
|
|
| 110 |
if line.strip() == "[DONE]":
|
| 111 |
break
|
| 112 |
|
| 113 |
+
try:
|
| 114 |
+
if line.startswith("data:"):
|
| 115 |
+
line = line[5:].strip()
|
| 116 |
+
|
| 117 |
+
if line:
|
| 118 |
+
chunk = json.loads(line)
|
| 119 |
+
chunk_message = chunk.get("chunk", {}).get("content", "")
|
| 120 |
+
assistant_reply += chunk_message
|
| 121 |
+
yield assistant_reply
|
| 122 |
+
except json.JSONDecodeError as e:
|
| 123 |
+
print(f"Stream chunk error: {e} with line: {line}")
|
| 124 |
|
| 125 |
|
| 126 |
|