KevinHuSh
commited on
Commit
路
66d269d
1
Parent(s):
f4cd7c3
fix zhipuAI stream issue (#825)
Browse files### What problem does this PR solve?
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/api_app.py +1 -1
- api/apps/conversation_app.py +1 -1
- rag/llm/chat_model.py +3 -2
api/apps/api_app.py
CHANGED
|
@@ -222,7 +222,7 @@ def completion():
|
|
| 222 |
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
| 223 |
return resp
|
| 224 |
else:
|
| 225 |
-
ans = chat(dia, msg,
|
| 226 |
fillin_conv(ans)
|
| 227 |
API4ConversationService.append_message(conv.id, conv.to_dict())
|
| 228 |
return get_json_result(data=ans)
|
|
|
|
| 222 |
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
| 223 |
return resp
|
| 224 |
else:
|
| 225 |
+
ans = chat(dia, msg, **req)
|
| 226 |
fillin_conv(ans)
|
| 227 |
API4ConversationService.append_message(conv.id, conv.to_dict())
|
| 228 |
return get_json_result(data=ans)
|
api/apps/conversation_app.py
CHANGED
|
@@ -162,7 +162,7 @@ def completion():
|
|
| 162 |
return resp
|
| 163 |
|
| 164 |
else:
|
| 165 |
-
ans = chat(dia, msg,
|
| 166 |
fillin_conv(ans)
|
| 167 |
ConversationService.update_by_id(conv.id, conv.to_dict())
|
| 168 |
return get_json_result(data=ans)
|
|
|
|
| 162 |
return resp
|
| 163 |
|
| 164 |
else:
|
| 165 |
+
ans = chat(dia, msg, **req)
|
| 166 |
fillin_conv(ans)
|
| 167 |
ConversationService.update_by_id(conv.id, conv.to_dict())
|
| 168 |
return get_json_result(data=ans)
|
rag/llm/chat_model.py
CHANGED
|
@@ -193,10 +193,11 @@ class ZhipuChat(Base):
|
|
| 193 |
if not resp.choices[0].delta.content:continue
|
| 194 |
delta = resp.choices[0].delta.content
|
| 195 |
ans += delta
|
| 196 |
-
|
| 197 |
-
if resp.output.choices[0].finish_reason == "length":
|
| 198 |
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
| 199 |
[ans]) else "路路路路路路\n鐢变簬闀垮害鐨勫師鍥狅紝鍥炵瓟琚埅鏂簡锛岃缁х画鍚楋紵"
|
|
|
|
|
|
|
| 200 |
yield ans
|
| 201 |
except Exception as e:
|
| 202 |
yield ans + "\n**ERROR**: " + str(e)
|
|
|
|
| 193 |
if not resp.choices[0].delta.content:continue
|
| 194 |
delta = resp.choices[0].delta.content
|
| 195 |
ans += delta
|
| 196 |
+
if resp.choices[0].finish_reason == "length":
|
|
|
|
| 197 |
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
| 198 |
[ans]) else "路路路路路路\n鐢变簬闀垮害鐨勫師鍥狅紝鍥炵瓟琚埅鏂簡锛岃缁х画鍚楋紵"
|
| 199 |
+
tk_count = resp.usage.total_tokens
|
| 200 |
+
if resp.choices[0].finish_reason == "stop": tk_count = resp.usage.total_tokens
|
| 201 |
yield ans
|
| 202 |
except Exception as e:
|
| 203 |
yield ans + "\n**ERROR**: " + str(e)
|