It fixes 2 exceptions on Azure GPT-4
1)
Traceback (most recent call last):
File "/opt/homebrew/bin//aider", line 8, in <module>
sys.exit(main())
File "/opt/homebrew/lib/python3.10/site-packages/aider/main.py", line 523, in main
coder.run()
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 339, in run
new_user_message = self.run_loop()
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 423, in run_loop
return self.send_new_user_message(inp)
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 456, in send_new_user_message
interrupted = self.send(messages, functions=self.functions)
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 580, in send
self.show_send_output_stream(completion)
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 680, in show_send_output_stream
sys.stdout.write(text)
UnboundLocalError: local variable 'text' referenced before assignment
2)
Traceback (most recent call last):
File "/opt/homebrew/bin//aider", line 8, in <module>
sys.exit(main())
File "/opt/homebrew/lib/python3.10/site-packages/aider/main.py", line 523, in main
coder.run()
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 339, in run
new_user_message = self.run_loop()
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 423, in run_loop
return self.send_new_user_message(inp)
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 456, in send_new_user_message
interrupted = self.send(messages, functions=self.functions)
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 580, in send
self.show_send_output_stream(completion)
File "/opt/homebrew/lib/python3.10/site-packages/aider/coders/base_coder.py", line 656, in show_send_output_stream
if chunk.choices[0].finish_reason == "length":
IndexError: list index out of range
# 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>
# 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>