mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix miscalculated token count (#9776)
### What problem does this PR solve? The total token was incorrectly accumulated when using the OpenAI-API-Compatible api. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -374,7 +374,7 @@ class Base(ABC):
|
|||||||
if not tol:
|
if not tol:
|
||||||
total_tokens += num_tokens_from_string(resp.choices[0].delta.content)
|
total_tokens += num_tokens_from_string(resp.choices[0].delta.content)
|
||||||
else:
|
else:
|
||||||
total_tokens += tol
|
total_tokens = tol
|
||||||
|
|
||||||
finish_reason = resp.choices[0].finish_reason if hasattr(resp.choices[0], "finish_reason") else ""
|
finish_reason = resp.choices[0].finish_reason if hasattr(resp.choices[0], "finish_reason") else ""
|
||||||
if finish_reason == "length":
|
if finish_reason == "length":
|
||||||
@ -410,7 +410,7 @@ class Base(ABC):
|
|||||||
if not tol:
|
if not tol:
|
||||||
total_tokens += num_tokens_from_string(resp.choices[0].delta.content)
|
total_tokens += num_tokens_from_string(resp.choices[0].delta.content)
|
||||||
else:
|
else:
|
||||||
total_tokens += tol
|
total_tokens = tol
|
||||||
answer += resp.choices[0].delta.content
|
answer += resp.choices[0].delta.content
|
||||||
yield resp.choices[0].delta.content
|
yield resp.choices[0].delta.content
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user