Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -107,14 +107,21 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
| 107 |
assistant_reply = ""
|
| 108 |
for line in response.iter_lines(decode_unicode=True):
|
| 109 |
print(f"Received line: {line}") # Debugging
|
| 110 |
-
|
|
|
|
| 111 |
try:
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|
|
|
|
| 107 |
assistant_reply = ""
|
| 108 |
for line in response.iter_lines(decode_unicode=True):
|
| 109 |
print(f"Received line: {line}") # Debugging
|
| 110 |
+
|
| 111 |
+
if line.strip(): # Ignore empty or whitespace-only lines
|
| 112 |
try:
|
| 113 |
+
# Remove 'data: ' prefix if present
|
| 114 |
+
if line.startswith("data:"):
|
| 115 |
+
line = line[5:].strip()
|
| 116 |
+
|
| 117 |
+
if line: # Ensure there's content after stripping
|
| 118 |
+
chunk = json.loads(line) # Parse JSON
|
| 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 |
|
| 127 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|