From 114192e025e007e3afec265c5bb6da5bc54d6852 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Thu, 4 Jul 2024 20:28:53 +0800 Subject: [PATCH] Bug fix: can not chat with deepseek (#1879) --- request_llms/oai_std_model_template.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/request_llms/oai_std_model_template.py b/request_llms/oai_std_model_template.py index 1d649af96..2f8480c41 100644 --- a/request_llms/oai_std_model_template.py +++ b/request_llms/oai_std_model_template.py @@ -44,7 +44,7 @@ def decode_chunk(chunk): try: chunk = json.loads(chunk[6:]) except: - respose = "API_ERROR" + respose = "" finish_reason = chunk # 错误处理部分 if "error" in chunk: @@ -200,10 +200,13 @@ def predict_no_ui_long_connection( stream_response = response.iter_lines() result = "" + finish_reason = "" while True: try: chunk = next(stream_response) except StopIteration: + if result == "": + raise RuntimeError(f"获得空的回复,可能原因:{finish_reason}") break except requests.exceptions.ConnectionError: chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。 @@ -351,6 +354,10 @@ def predict( response_text, finish_reason = decode_chunk(chunk) # 返回的数据流第一次为空,继续等待 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 if chunk: try: