From f21ef30482577e92e75b5326495db01289cf345a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 4 Feb 2025 12:31:10 -0800 Subject: [PATCH] feat: Add methods to identify deepseek and ollama models --- aider/models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aider/models.py b/aider/models.py index e5544ae99..7e8a8ec9d 100644 --- a/aider/models.py +++ b/aider/models.py @@ -529,11 +529,20 @@ class Model(ModelSettings): map_tokens = max(map_tokens, 1024) return map_tokens + def is_deepseek_r1(self): + name = self.name.lower() + if "deepseek" not in name: + return + return "r1" in name or "reasoner" in name + + def is_ollama(self): + return self.name.startswith("ollama/") or self.name.startswith("ollama_chat/") + def send_completion(self, messages, functions, stream, temperature=0): if os.environ.get("AIDER_SANITY_CHECK_TURNS"): sanity_check_messages(messages) - if "deepseek-reasoner" in self.name: + if self.is_deepseek_r1(): messages = ensure_alternating_roles(messages) kwargs = dict( @@ -552,6 +561,8 @@ class Model(ModelSettings): if self.extra_params: kwargs.update(self.extra_params) + # if is_ollama and kwargs[num_ctx] isn't set: num_ctx = token_count(messages) * 1.5 ai! + key = json.dumps(kwargs, sort_keys=True).encode() # dump(kwargs) hash_object = hashlib.sha1(key)