Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,22 +106,25 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 106 |
if response.status_code == 200:
|
| 107 |
assistant_reply = ""
|
| 108 |
for line in response.iter_lines(decode_unicode=True):
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
try:
|
| 113 |
-
if line.startswith("data:"):
|
| 114 |
-
line = line[5:].strip()
|
| 115 |
-
|
| 116 |
-
if line:
|
| 117 |
-
chunk = json.loads(line)
|
| 118 |
-
chunk_message = chunk.get("chunk", {}).get("content", "")
|
| 119 |
-
assistant_reply += chunk_message
|
| 120 |
-
yield assistant_reply
|
| 121 |
-
except json.JSONDecodeError as e:
|
| 122 |
-
print(f"Stream chunk error: {e} with line: {line}")
|
| 123 |
|
|
|
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|
| 127 |
sessions[api_key]["history"] = history
|
|
|
|
| 106 |
if response.status_code == 200:
|
| 107 |
assistant_reply = ""
|
| 108 |
for line in response.iter_lines(decode_unicode=True):
|
| 109 |
+
line = line.strip()
|
| 110 |
+
if not line:
|
| 111 |
+
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 |
+
continue
|
| 128 |
|
| 129 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|
| 130 |
sessions[api_key]["history"] = history
|