feat: Track total tokens and use in benchmark stats

This commit is contained in:
Paul Gauthier (aider) 2025-05-07 21:08:29 -07:00
parent a98b531bcc
commit 5090f28151
2 changed files with 15 additions and 4 deletions

View file

@ -108,8 +108,6 @@ class Coder:
partial_response_content = ""
commit_before_message = []
message_cost = 0.0
message_tokens_sent = 0
message_tokens_received = 0
add_cache_headers = False
cache_warming_thread = None
num_cache_warming_pings = 0
@ -128,6 +126,8 @@ class Coder:
from_coder=None,
summarize_from_coder=True,
**kwargs,
):
import aider.coders as coders
@ -175,6 +175,8 @@ class Coder:
commands=from_coder.commands.clone(),
total_cost=from_coder.total_cost,
ignore_mentions=from_coder.ignore_mentions,
total_tokens_sent=from_coder.total_tokens_sent,
total_tokens_received=from_coder.total_tokens_received,
file_watcher=from_coder.file_watcher,
)
use_kwargs.update(update) # override to complete the switch
@ -327,6 +329,8 @@ class Coder:
chat_language=None,
detect_urls=True,
ignore_mentions=None,
total_tokens_sent=0,
total_tokens_received=0,
file_watcher=None,
auto_copy_context=False,
auto_accept_architect=True,
@ -373,6 +377,10 @@ class Coder:
self.need_commit_before_edits = set()
self.total_cost = total_cost
self.total_tokens_sent = total_tokens_sent
self.total_tokens_received = total_tokens_received
self.message_tokens_sent = 0
self.message_tokens_received = 0
self.verbose = verbose
self.abs_fnames = set()
@ -2057,6 +2065,9 @@ class Coder:
if not self.usage_report:
return
self.total_tokens_sent += self.message_tokens_sent
self.total_tokens_received += self.message_tokens_received
self.io.tool_output(self.usage_report)
prompt_tokens = self.message_tokens_sent

View file

@ -957,8 +957,8 @@ def run_test_real(
indentation_errors=indentation_errors,
lazy_comments=lazy_comments, # Add the count of pattern matches to the results
reasoning_effort=reasoning_effort,
prompt_tokens=coder.message_tokens_sent,
completion_tokens=coder.message_tokens_received,
prompt_tokens=coder.total_tokens_sent,
completion_tokens=coder.total_tokens_received,
thinking_tokens=thinking_tokens,
chat_hashes=list(
zip(