Spaces:
Sleeping
Sleeping
Commit
•
df985e4
1
Parent(s):
1620ce5
Upload 3 files
Browse files
utils.py
CHANGED
@@ -156,6 +156,7 @@ def stream_predict(openai_api_key, system_prompt, history, inputs, chatbot, all_
|
|
156 |
return
|
157 |
|
158 |
yield get_return_value()
|
|
|
159 |
|
160 |
for chunk in tqdm(response.iter_lines()):
|
161 |
if counter == 0:
|
@@ -170,7 +171,8 @@ def stream_predict(openai_api_key, system_prompt, history, inputs, chatbot, all_
|
|
170 |
chunk = json.loads(chunk[6:])
|
171 |
except json.JSONDecodeError:
|
172 |
print(chunk)
|
173 |
-
|
|
|
174 |
yield get_return_value()
|
175 |
continue
|
176 |
# decode each line as response data is in bytes
|
@@ -224,10 +226,13 @@ def predict(openai_api_key, system_prompt, history, inputs, chatbot, all_token_c
|
|
224 |
if len(openai_api_key) != 51:
|
225 |
status_text = standard_error_msg + no_apikey_msg
|
226 |
print(status_text)
|
227 |
-
history.append(construct_user(inputs))
|
228 |
-
history.append("")
|
229 |
chatbot.append((parse_text(inputs), ""))
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
231 |
yield chatbot, history, status_text, all_token_counts
|
232 |
return
|
233 |
yield chatbot, history, "开始生成回答……", all_token_counts
|
|
|
156 |
return
|
157 |
|
158 |
yield get_return_value()
|
159 |
+
error_json_str = ""
|
160 |
|
161 |
for chunk in tqdm(response.iter_lines()):
|
162 |
if counter == 0:
|
|
|
171 |
chunk = json.loads(chunk[6:])
|
172 |
except json.JSONDecodeError:
|
173 |
print(chunk)
|
174 |
+
error_json_str += chunk
|
175 |
+
status_text = f"JSON解析错误。请重置对话。收到的内容: {error_json_str}"
|
176 |
yield get_return_value()
|
177 |
continue
|
178 |
# decode each line as response data is in bytes
|
|
|
226 |
if len(openai_api_key) != 51:
|
227 |
status_text = standard_error_msg + no_apikey_msg
|
228 |
print(status_text)
|
|
|
|
|
229 |
chatbot.append((parse_text(inputs), ""))
|
230 |
+
if len(history) == 0:
|
231 |
+
history.append(construct_user(inputs))
|
232 |
+
history.append("")
|
233 |
+
all_token_counts.append(0)
|
234 |
+
else:
|
235 |
+
history[-2] = construct_user(inputs)
|
236 |
yield chatbot, history, status_text, all_token_counts
|
237 |
return
|
238 |
yield chatbot, history, "开始生成回答……", all_token_counts
|