From d24376608e669504ee4b739639ca894c94a5ce05 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 4 Jan 2025 06:18:15 -0800 Subject: [PATCH] refactor: generalize token calculation using division in Model class --- aider/models.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/aider/models.py b/aider/models.py index 256a1918f..4d46885af 100644 --- a/aider/models.py +++ b/aider/models.py @@ -920,13 +920,8 @@ class Model(ModelSettings): self.keys_in_environment = res.get("keys_in_environment") max_input_tokens = self.info.get("max_input_tokens") or 0 - # generalize this with division. ai! - if max_input_tokens < 16 * 1024: - self.max_chat_history_tokens = 1 * 1024 - elif max_input_tokens < 32 * 1024: - self.max_chat_history_tokens = 2 * 1024 - else: - self.max_chat_history_tokens = 4 * 1024 + # Calculate max_chat_history_tokens as 1/16th of max_input_tokens, with minimum 1k and maximum 4k + self.max_chat_history_tokens = min(max(max_input_tokens // 16, 1024), 4096) self.configure_model_settings(model) if weak_model is False: