From 2094b3176bd69ca94d1e70400db3c1ce2a0b43b1 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 26 Jul 2023 17:35:42 -0300 Subject: [PATCH] aider: Adjusted the calculation of the cost in the `cmd_tokens` method to account for the prices in `Model` being per 1k tokens. # Aider chat conversation: USER: the prices in `Model` are per 1k tokens ASSISTANT: I see, the prices in the `Model` class are per 1k tokens. Therefore, we need to adjust the calculation of the cost in the `cmd_tokens` method in the `Commands` class in the `aider/commands.py` file. We will divide the `completion_price` by 1000 before multiplying it with the token count to get the cost. Here are the changes: python aider/commands.py <<<<<<< ORIGINAL 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})") ======= total = 0 total_cost = 0.0 for tk, msg, tip in res: total += tk cost = tk * (self.coder.main_model.completion_price / 1000) 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 --- aider/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 8f8e4ac26..ebb5c4fb9 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -145,7 +145,7 @@ class Commands: total_cost = 0.0 for tk, msg, tip in res: total += tk - cost = tk * self.coder.main_model.completion_price + cost = tk * (self.coder.main_model.completion_price / 1000) total_cost += cost msg = msg.ljust(col_width) self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})")