Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -112,7 +112,21 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 112 |
|
| 113 |
print(f"Received line: {line}")
|
| 114 |
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
line_content = line[5:].strip()
|
| 117 |
if not line_content:
|
| 118 |
continue
|
|
|
|
| 112 |
|
| 113 |
print(f"Received line: {line}")
|
| 114 |
|
| 115 |
+
if line.startswith("data:"):
|
| 116 |
+
line_content = line[5:].strip()
|
| 117 |
+
if not line_content:
|
| 118 |
+
continue
|
| 119 |
+
|
| 120 |
+
try:
|
| 121 |
+
chunk = json.loads(line_content)
|
| 122 |
+
chunk_message = chunk.get("chunk", {}).get("content", "")
|
| 123 |
+
assistant_reply += chunk_message
|
| 124 |
+
yield assistant_reply
|
| 125 |
+
except json.JSONDecodeError as e:
|
| 126 |
+
print(f"Stream chunk error: {e} with line: {line_content}")
|
| 127 |
+
yield f"Error in stream chunk: {e}" # Optionally notify the user
|
| 128 |
+
continue
|
| 129 |
+
|
| 130 |
line_content = line[5:].strip()
|
| 131 |
if not line_content:
|
| 132 |
continue
|