Bug fix: can not chat with deepseek (#1879)

这个提交包含在:
Menghuan1918
2024-07-04 20:28:53 +08:00
提交者 GitHub
父节点 0c6c357e9c
当前提交 114192e025

查看文件

@@ -44,7 +44,7 @@ def decode_chunk(chunk):
try: try:
chunk = json.loads(chunk[6:]) chunk = json.loads(chunk[6:])
except: except:
respose = "API_ERROR" respose = ""
finish_reason = chunk finish_reason = chunk
# 错误处理部分 # 错误处理部分
if "error" in chunk: if "error" in chunk:
@@ -200,10 +200,13 @@ def get_predict_function(
stream_response = response.iter_lines() stream_response = response.iter_lines()
result = "" result = ""
finish_reason = ""
while True: while True:
try: try:
chunk = next(stream_response) chunk = next(stream_response)
except StopIteration: except StopIteration:
if result == "":
raise RuntimeError(f"获得空的回复,可能原因:{finish_reason}")
break break
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。 chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。
@@ -351,6 +354,10 @@ def get_predict_function(
response_text, finish_reason = decode_chunk(chunk) response_text, finish_reason = decode_chunk(chunk)
# 返回的数据流第一次为空,继续等待 # 返回的数据流第一次为空,继续等待
if response_text == "" and finish_reason != "False": if response_text == "" and finish_reason != "False":
status_text = f"finish_reason: {finish_reason}"
yield from update_ui(
chatbot=chatbot, history=history, msg=status_text
)
continue continue
if chunk: if chunk:
try: try: