From e48fecee14693162189eec29d92117a45ece7917 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 07:45:39 -0300 Subject: [PATCH] fix: Handle missing model info values gracefully --- aider/coders/base_coder.py | 6 +++--- aider/commands.py | 4 ++-- aider/models.py | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 35c3ac8d5..ddf9e85e5 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -852,7 +852,7 @@ class Coder: final = messages[-1] - max_input_tokens = self.main_model.info.get("max_input_tokens") + max_input_tokens = self.main_model.info.get("max_input_tokens") or 0 # Add the reminder prompt if we still have room to include it. if ( max_input_tokens is None @@ -1011,10 +1011,10 @@ class Coder: output_tokens = 0 if self.partial_response_content: output_tokens = self.main_model.token_count(self.partial_response_content) - max_output_tokens = self.main_model.info.get("max_output_tokens", 0) + max_output_tokens = self.main_model.info.get("max_output_tokens") or 0 input_tokens = self.main_model.token_count(self.format_messages()) - max_input_tokens = self.main_model.info.get("max_input_tokens", 0) + max_input_tokens = self.main_model.info.get("max_input_tokens") or 0 total_tokens = input_tokens + output_tokens diff --git a/aider/commands.py b/aider/commands.py index a1a225261..5ec6e451c 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -344,7 +344,7 @@ class Commands: total_cost = 0.0 for tk, msg, tip in res: total += tk - cost = tk * self.coder.main_model.info.get("input_cost_per_token", 0) + cost = tk * (self.coder.main_model.info.get("input_cost_per_token") or 0) total_cost += cost msg = msg.ljust(col_width) self.io.tool_output(f"${cost:7.4f} {fmt(tk)} {msg} {tip}") # noqa: E231 @@ -352,7 +352,7 @@ class Commands: self.io.tool_output("=" * (width + cost_width + 1)) self.io.tool_output(f"${total_cost:7.4f} {fmt(total)} tokens total") # noqa: E231 - limit = self.coder.main_model.info.get("max_input_tokens", 0) + limit = self.coder.main_model.info.get("max_input_tokens") or 0 if not limit: return diff --git a/aider/models.py b/aider/models.py index 344fc9d78..12a8a8046 100644 --- a/aider/models.py +++ b/aider/models.py @@ -405,9 +405,7 @@ class Model: self.missing_keys = res.get("missing_keys") self.keys_in_environment = res.get("keys_in_environment") - max_input_tokens = self.info.get("max_input_tokens") - if not max_input_tokens: - max_input_tokens = 0 + max_input_tokens = self.info.get("max_input_tokens") or 0 if max_input_tokens < 32 * 1024: self.max_chat_history_tokens = 1024 else: