feat: handle cost calculation differently for context window vs other errors

This commit is contained in:
Paul Gauthier (aider) 2024-12-09 07:45:50 -08:00
parent f009e8fb14
commit 6aa80d2a4c

View file

@ -1559,6 +1559,16 @@ class Coder:
yield from self.show_send_output_stream(completion)
else:
self.show_send_output(completion)
# Calculate costs for successful responses
self.calculate_and_show_tokens_and_cost(messages, completion)
except litellm_ex.exceptions_tuple() as err:
ex_info = litellm_ex.get_ex_info(err)
if ex_info.name == "ContextWindowExceededError":
# Still calculate costs for context window errors
self.calculate_and_show_tokens_and_cost(messages, completion)
raise
except KeyboardInterrupt as kbi:
self.keyboard_interrupt()
raise kbi
@ -1576,8 +1586,6 @@ class Coder:
if args:
self.io.ai_output(json.dumps(args, indent=4))
self.calculate_and_show_tokens_and_cost(messages, completion)
def show_send_output(self, completion):
if self.verbose:
print(completion)