mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 08:14:59 +00:00
aider: Updated the output of /tokens
to include the total cost.
# Aider chat conversation: USER: udpate the output of /tokens to include the total $ cost ASSISTANT: To include the total cost in the output of the `/tokens` command, we need to modify the `cmd_tokens` method in the `Commands` class in the `aider/commands.py` file. We will add a new variable `total_cost` to keep track of the total cost. For each token count, we will calculate the cost by multiplying the token count by the model's `completion_price` (since we're considering the cost of generating these tokens). We will then add this cost to `total_cost`. Finally, we will add a line to the output to display the total cost. Here are the changes: <source>python aider/commands.py <<<<<<< ORIGINAL total = 0 for tk, msg, tip in res: total += tk msg = msg.ljust(col_width) self.io.tool_output(f"{fmt(tk)} {msg} {tip}") self.io.tool_output("=" * width) self.io.tool_output(f"{fmt(total)} tokens total") ======= total = 0 total_cost = 0.0 for tk, msg, tip in res: total += tk cost = tk * self.coder.main_model.completion_price total_cost += cost msg = msg.ljust(col_width) self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})") self.io.tool_output("=" * width) self.io.tool_output(f"{fmt(total)} tokens total (cost: ${total_cost:.2f})") >>>>>>> UPDATED </source>
This commit is contained in:
parent
08ee61617f
commit
35ccfac3fd
1 changed files with 5 additions and 2 deletions
|
@ -142,13 +142,16 @@ class Commands:
|
|||
col_width = max(len(row[1]) for row in res)
|
||||
|
||||
total = 0
|
||||
total_cost = 0.0
|
||||
for tk, msg, tip in res:
|
||||
total += tk
|
||||
cost = tk * self.coder.main_model.completion_price
|
||||
total_cost += cost
|
||||
msg = msg.ljust(col_width)
|
||||
self.io.tool_output(f"{fmt(tk)} {msg} {tip}")
|
||||
self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})")
|
||||
|
||||
self.io.tool_output("=" * width)
|
||||
self.io.tool_output(f"{fmt(total)} tokens total")
|
||||
self.io.tool_output(f"{fmt(total)} tokens total (cost: ${total_cost:.2f})")
|
||||
|
||||
limit = self.coder.main_model.max_context_tokens
|
||||
remaining = limit - total
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue