Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

[Bug]: When use OpenAI chat model , raise ERROR: 'CompletionUsage' object has no attribute 'get' #2948 (#2949)

Yinquan WANG5aa9d7787ed0
diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py
index 58d5b0ded6..1dbf509351 100644
--- a/rag/llm/chat_model.py
+++ b/rag/llm/chat_model.py
@@ -67,6 +67,7 @@ class Base(ABC):
if not resp.choices[0].delta.content:
resp.choices[0].delta.content = ""
ans += resp.choices[0].delta.content
+
total_tokens += 1
if not hasattr(resp, "usage") or not resp.usage:
total_tokens = (