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:

<source>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
</source>
This commit is contained in:
Paul Gauthier 2023-07-26 17:35:42 -03:00
parent 35ccfac3fd
commit 2094b3176b

View file

@ -145,7 +145,7 @@ class Commands:
total_cost = 0.0 total_cost = 0.0
for tk, msg, tip in res: for tk, msg, tip in res:
total += tk total += tk
cost = tk * self.coder.main_model.completion_price cost = tk * (self.coder.main_model.completion_price / 1000)
total_cost += cost total_cost += cost
msg = msg.ljust(col_width) msg = msg.ljust(col_width)
self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})") self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})")