Wang Baoling commited on
Commit
4eabbf5
·
1 Parent(s): 95ccaf9

fix: ERROR: 'CompletionUsage' object has no attribute 'get' (#1736)

Browse files

### What problem does this PR solve?

_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Files changed (1) hide show
  1. rag/llm/chat_model.py +1 -1
rag/llm/chat_model.py CHANGED
@@ -183,7 +183,7 @@ class BaiChuanChat(Base):
183
  if resp.choices[0].finish_reason == "stop":
184
  if not resp.choices[0].delta.content:
185
  continue
186
- total_tokens = resp.usage.get('total_tokens', 0)
187
  if not resp.choices[0].delta.content:
188
  continue
189
  ans += resp.choices[0].delta.content
 
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