feat: Add methods to identify deepseek and ollama models

This commit is contained in:
Paul Gauthier 2025-02-04 12:31:10 -08:00 committed by Paul Gauthier (aider)
parent 606fce65ab
commit f21ef30482

View file

@ -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)