榛勮吘 aopstudio commited on
Commit
cbc2f9a
1 Parent(s): 81364e6

lower openai version in requirements.txt (#1747)

Browse files

### What problem does this PR solve?

lower openai version in requirements.txt

### Type of change

- [x] Refactoring

Co-authored-by: Zhedong Cen <[email protected]>

Files changed (2) hide show
  1. rag/llm/chat_model.py +10 -5
  2. requirements.txt +1 -1
rag/llm/chat_model.py CHANGED
@@ -180,13 +180,18 @@ class BaiChuanChat(Base):
180
  stream=True,
181
  **self._format_params(gen_conf))
182
  for resp in response:
183
- if resp.choices[0].finish_reason == "stop":
184
- if not resp.choices[0].delta.content:
185
- continue
186
- total_tokens = resp.usage.total_tokens
187
  if not resp.choices[0].delta.content:
188
- continue
189
  ans += resp.choices[0].delta.content
 
 
 
 
 
 
 
 
190
  if resp.choices[0].finish_reason == "length":
191
  ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
192
  [ans]) else "路路路路路路\n鐢变簬闀垮害鐨勫師鍥狅紝鍥炵瓟琚埅鏂簡锛岃缁х画鍚楋紵"
 
180
  stream=True,
181
  **self._format_params(gen_conf))
182
  for resp in response:
183
+ if not resp.choices:continue
 
 
 
184
  if not resp.choices[0].delta.content:
185
+ resp.choices[0].delta.content = ""
186
  ans += resp.choices[0].delta.content
187
+ total_tokens = (
188
+ (
189
+ total_tokens
190
+ + num_tokens_from_string(resp.choices[0].delta.content)
191
+ )
192
+ if not hasattr(resp, "usage")
193
+ else resp.usage["total_tokens"]
194
+ )
195
  if resp.choices[0].finish_reason == "length":
196
  ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
197
  [ans]) else "路路路路路路\n鐢变簬闀垮害鐨勫師鍥狅紝鍥炵瓟琚埅鏂簡锛岃缁х画鍚楋紵"
requirements.txt CHANGED
@@ -39,7 +39,7 @@ numpy==1.26.4
39
  ollama==0.2.1
40
  onnxruntime==1.17.3
41
  onnxruntime_gpu==1.17.1
42
- openai==1.35.14
43
  opencv_python==4.9.0.80
44
  opencv_python_headless==4.9.0.80
45
  openpyxl==3.1.2
 
39
  ollama==0.2.1
40
  onnxruntime==1.17.3
41
  onnxruntime_gpu==1.17.1
42
+ openai==1.12.0
43
  opencv_python==4.9.0.80
44
  opencv_python_headless==4.9.0.80
45
  openpyxl==3.1.2