mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 05:02:01 -06:00
fix: tool calls make chats compact too early and inflate prompt token counts (#33218)
Since a recent refactor on dev, the prompt and completion token counts of a reply that used tools added up every model call in the loop, even though each later call already re-sends the whole conversation. A reply whose context was 50k tokens showed 90k, the context gauge read over 100% and the next message triggered compaction long before the chat reached the threshold. Prompt and completion tokens show the latest call again, while total tokens and cost still add up across all calls.
This commit is contained in:
@@ -138,10 +138,10 @@ def merge_usage(current: dict | None, incoming: dict | None) -> dict:
|
||||
incoming_usage.get(key) if isinstance(incoming_usage.get(key), dict) else {},
|
||||
)
|
||||
|
||||
# Aliases mirror the cumulative canonical values, including a measured zero.
|
||||
# Aliases keep the latest call's size, which context compaction reads.
|
||||
for alias, canonical in (('prompt_tokens', 'input_tokens'), ('completion_tokens', 'output_tokens')):
|
||||
if canonical in result:
|
||||
result[alias] = result[canonical]
|
||||
if canonical in incoming_usage:
|
||||
result[alias] = incoming_usage[canonical]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user