diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index fb6fca8b2..e021b9dda 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -180,13 +180,18 @@ class BaiChuanChat(Base): stream=True, **self._format_params(gen_conf)) for resp in response: - if resp.choices[0].finish_reason == "stop": - if not resp.choices[0].delta.content: - continue - total_tokens = resp.usage.total_tokens + if not resp.choices:continue if not resp.choices[0].delta.content: - continue + resp.choices[0].delta.content = "" ans += resp.choices[0].delta.content + total_tokens = ( + ( + total_tokens + + num_tokens_from_string(resp.choices[0].delta.content) + ) + if not hasattr(resp, "usage") + else resp.usage["total_tokens"] + ) if resp.choices[0].finish_reason == "length": ans += "...\nFor the content length reason, it stopped, continue?" if is_english( [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" diff --git a/requirements.txt b/requirements.txt index fa57cfded..b336f7df8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -39,7 +39,7 @@ numpy==1.26.4 ollama==0.2.1 onnxruntime==1.17.3 onnxruntime_gpu==1.17.1 -openai==1.35.14 +openai==1.12.0 opencv_python==4.9.0.80 opencv_python_headless==4.9.0.80 openpyxl==3.1.2