Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,24 +104,23 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 104 |
response = requests.post(API_URL, headers=headers, data=json.dumps(data), stream=True)
|
| 105 |
|
| 106 |
if response.status_code == 200:
|
| 107 |
-
assistant_reply = ""
|
| 108 |
for line in response.iter_lines(decode_unicode=True):
|
| 109 |
if line.strip():
|
| 110 |
-
|
| 111 |
-
break
|
| 112 |
-
|
| 113 |
-
try:
|
| 114 |
if line.startswith("data:"):
|
| 115 |
-
|
| 116 |
-
|
| 117 |
if line:
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|
|
|
|
| 104 |
response = requests.post(API_URL, headers=headers, data=json.dumps(data), stream=True)
|
| 105 |
|
| 106 |
if response.status_code == 200:
|
|
|
|
| 107 |
for line in response.iter_lines(decode_unicode=True):
|
| 108 |
if line.strip():
|
| 109 |
+
try:
|
|
|
|
|
|
|
|
|
|
| 110 |
if line.startswith("data:"):
|
| 111 |
+
line = line[5:].strip()
|
| 112 |
+
|
| 113 |
if line:
|
| 114 |
+
chunk = json.loads(line)
|
| 115 |
+
chunk_message = chunk.get("chunk", {}).get("content", "")
|
| 116 |
+
assistant_reply += chunk_message
|
| 117 |
+
|
| 118 |
+
partial_history = history + [(message, assistant_reply, "You", "P-ALPLE", session["avatar"], ASSISTANT_PIC_PATH)]
|
| 119 |
+
sessions[api_key]["history"] = partial_history
|
| 120 |
+
|
| 121 |
+
yield assistant_reply
|
| 122 |
+
except json.JSONDecodeError as e:
|
| 123 |
+
print(f"Stream chunk error: {e} with line: {line}")
|
| 124 |
|
| 125 |
|
| 126 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|