Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -99,34 +99,28 @@ def respond(message, api_key, max_tokens, top_p, temperature):
|
|
99 |
"input": message,
|
100 |
"stream": True
|
101 |
}
|
102 |
-
|
103 |
-
|
104 |
try:
|
105 |
response = requests.post(API_URL, headers=headers, data=json.dumps(data), stream=True)
|
106 |
|
107 |
if response.status_code == 200:
|
108 |
assistant_reply = ""
|
109 |
for line in response.iter_lines(decode_unicode=True):
|
110 |
-
line
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
yield assistant_reply
|
126 |
-
except json.JSONDecodeError as e:
|
127 |
-
print(f"Stream chunk error: {e} with line: {line_content}")
|
128 |
-
yield f"Error in stream chunk: {e}" # Optionally notify the user
|
129 |
-
continue
|
130 |
|
131 |
|
132 |
history.append((message, assistant_reply, "You", "P-ALPLE", sessions[api_key]["avatar"], ASSISTANT_PIC_PATH))
|
|
|
99 |
"input": message,
|
100 |
"stream": True
|
101 |
}
|
102 |
+
|
|
|
103 |
try:
|
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 |
+
print(f"Received line: {line}")
|
110 |
+
|
111 |
+
if line.strip():
|
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))
|