diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 459e0205f..45758a63d 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -508,7 +508,7 @@ class Coder: messages += self.cur_messages # Add the reminder prompt if we still have room to include it. - if total_tokens < self.main_model.max_context_tokens: + if total_tokens < self.main_model.info.get("max_input_tokens", 0): messages += reminder_message return messages @@ -707,10 +707,10 @@ class Coder: completion_tokens = completion.usage.completion_tokens tokens = f"{prompt_tokens} prompt tokens, {completion_tokens} completion tokens" - if self.main_model.prompt_price: - cost = prompt_tokens * self.main_model.prompt_price / 1000 - if self.main_model.completion_price: - cost += completion_tokens * self.main_model.completion_price / 1000 + if self.main_model.info.get("input_cost_per_token"): + cost = prompt_tokens * self.main_model.info.get("input_cost_per_token") + if self.main_model.info.get("output_cost_per_token"): + cost += completion_tokens * self.main_model.info.get("output_cost_per_token") tokens += f", ${cost:.6f} cost" self.total_cost += cost diff --git a/aider/commands.py b/aider/commands.py index 602b11dd4..990d922f2 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -176,7 +176,7 @@ class Commands: self.io.tool_output() width = 8 - cost_width = 7 + cost_width = 9 def fmt(v): return format(int(v), ",").rjust(width) @@ -188,13 +188,13 @@ class Commands: total_cost = 0.0 for tk, msg, tip in res: total += tk - cost = tk * (self.coder.main_model.prompt_price / 1000) + cost = tk * self.coder.main_model.info.get("input_cost_per_token", 0) total_cost += cost msg = msg.ljust(col_width) - self.io.tool_output(f"${cost:5.2f} {fmt(tk)} {msg} {tip}") + self.io.tool_output(f"${cost:7.4f} {fmt(tk)} {msg} {tip}") self.io.tool_output("=" * (width + cost_width + 1)) - self.io.tool_output(f"${total_cost:5.2f} {fmt(total)} tokens total") + self.io.tool_output(f"${total_cost:7.4f} {fmt(total)} tokens total") # only switch to image model token count if gpt4 and openai and image in files image_in_chat = False @@ -203,7 +203,7 @@ class Commands: is_image_file(relative_fname) for relative_fname in self.coder.get_inchat_relative_files() ) - limit = 128000 if image_in_chat else self.coder.main_model.max_context_tokens + limit = 128000 if image_in_chat else self.coder.main_model.info.get("max_input_tokens") remaining = limit - total if remaining > 1024: diff --git a/aider/models/model.py b/aider/models/model.py index 6ca16d518..16e7c5116 100644 --- a/aider/models/model.py +++ b/aider/models/model.py @@ -4,22 +4,26 @@ import math import litellm from PIL import Image +from aider.dump import dump + class Model: name = None edit_format = "whole" - max_context_tokens = 0 - max_chat_history_tokens = 1024 - always_available = False use_repo_map = False send_undo_reply = False - - prompt_price = None - completion_price = None + max_chat_history_tokens = 1024 def __init__(self, model): self.name = model + self.info = litellm.get_model_info(model) + dump(self.info) + + if self.info.get("max_input_tokens", 0) < 32 * 1024: + self.max_chat_history_tokens = 1024 + else: + self.max_chat_history_tokens = 2 * 1024 def __str__(self): return self.name