Skip to content

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

Fix miscalculated token count (#9776)

Yuhao Bi91d6fb8061dc
diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py
index 98d71141c8..adc4a3c5af 100644
--- a/rag/llm/chat_model.py
+++ b/rag/llm/chat_model.py
@@ -374,7 +374,7 @@ class Base(ABC):
if not tol:
total_tokens += num_tokens_from_string(resp.choices[0].delta.content)
else:
- total_tokens += tol
+ total_tokens = tol
finish_reason = resp.choices[0].finish_reason if hasattr(resp.choices[0], "finish_reason") else ""
if finish_reason == "length":
@@ -410,7 +410,7 @@ class Base(ABC):
if not tol:
total_tokens += num_tokens_from_string(resp.choices[0].delta.content)
else:
- total_tokens += tol
+ total_tokens = tol
answer += resp.choices[0].delta.content
yield resp.choices[0].delta.content