mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
feat: Update calculate_and_show_tokens_and_cost
to format token counts
This commit is contained in:
parent
959a9fbcf1
commit
93fe9007f0
1 changed files with 12 additions and 4 deletions
|
@ -1502,13 +1502,21 @@ class Coder:
|
|||
|
||||
self.message_tokens_received += completion_tokens
|
||||
|
||||
tokens_report = f"Tokens: {self.message_tokens_sent:,} sent"
|
||||
def format_tokens(count):
|
||||
if count < 1000:
|
||||
return f"{count}"
|
||||
elif count < 10000:
|
||||
return f"{count/1000:.1f}k"
|
||||
else:
|
||||
return f"{count//1000}k"
|
||||
|
||||
tokens_report = f"Tokens: {format_tokens(self.message_tokens_sent)} sent"
|
||||
|
||||
if cache_write_tokens:
|
||||
tokens_report += f", {cache_write_tokens:,} cache write"
|
||||
tokens_report += f", {format_tokens(cache_write_tokens)} cache write"
|
||||
if cache_hit_tokens:
|
||||
tokens_report += f", {cache_hit_tokens:,} cache hit"
|
||||
tokens_report += f", {self.message_tokens_received:,} received."
|
||||
tokens_report += f", {format_tokens(cache_hit_tokens)} cache hit"
|
||||
tokens_report += f", {format_tokens(self.message_tokens_received)} received."
|
||||
|
||||
if not self.main_model.info.get("input_cost_per_token"):
|
||||
self.usage_report = tokens_report
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue