From 74ebc497c1c36a2631e7bc85a393e47a2bc5a76e Mon Sep 17 00:00:00 2001 From: Wang Baoling Date: Tue, 30 Jul 2024 15:12:16 +0800 Subject: [PATCH] fix: ERROR: 'CompletionUsage' object has no attribute 'get' (#1736) ### 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) --- rag/llm/chat_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index 9337bd6bf..fb6fca8b2 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -183,7 +183,7 @@ class BaiChuanChat(Base): if resp.choices[0].finish_reason == "stop": if not resp.choices[0].delta.content: continue - total_tokens = resp.usage.get('total_tokens', 0) + total_tokens = resp.usage.total_tokens if not resp.choices[0].delta.content: continue ans += resp.choices[0].delta.content