From 5cff780ec4633e0b4444b76df8d9d950dab3901a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=85=BE?= <101850389+hangters@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:55:59 +0800 Subject: [PATCH] lower openai version in requirements.txt (#1747) ### What problem does this PR solve? lower openai version in requirements.txt ### Type of change - [x] Refactoring Co-authored-by: Zhedong Cen --- rag/llm/chat_model.py | 15 ++++++++++----- requirements.txt | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) 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