Skip to content

Commit

Permalink
refactor: simplify detection of OpenAI or Anthropic models
Browse files Browse the repository at this point in the history
  • Loading branch information
Finndersen committed Jan 10, 2025
1 parent 37ad475 commit 551d357
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions aider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,6 @@
DEFAULT_MODEL_NAME = "gpt-4o"
ANTHROPIC_BETA_HEADER = "prompt-caching-2024-07-31,pdfs-2024-09-25"

OPENAI_MODELS = """
gpt-4
gpt-4o
gpt-4o-2024-05-13
gpt-4-turbo-preview
gpt-4-0314
gpt-4-0613
gpt-4-32k
gpt-4-32k-0314
gpt-4-32k-0613
gpt-4-turbo
gpt-4-turbo-2024-04-09
gpt-4-1106-preview
gpt-4-0125-preview
gpt-4-vision-preview
gpt-4-1106-vision-preview
gpt-4o-mini
gpt-4o-mini-2024-07-18
gpt-3.5-turbo
gpt-3.5-turbo-0301
gpt-3.5-turbo-0613
gpt-3.5-turbo-1106
gpt-3.5-turbo-0125
gpt-3.5-turbo-16k
gpt-3.5-turbo-16k-0613
"""

OPENAI_MODELS = [ln.strip() for ln in OPENAI_MODELS.splitlines() if ln.strip()]

ANTHROPIC_MODELS = """
claude-2
claude-2.1
claude-3-haiku-20240307
claude-3-5-haiku-20241022
claude-3-opus-20240229
claude-3-sonnet-20240229
claude-3-5-sonnet-20240620
claude-3-5-sonnet-20241022
"""

ANTHROPIC_MODELS = [ln.strip() for ln in ANTHROPIC_MODELS.splitlines() if ln.strip()]

# Mapping of model aliases to their canonical names
MODEL_ALIASES = {
Expand Down Expand Up @@ -1143,9 +1102,9 @@ def fast_validate_environment(self):
"""Fast path for common models. Avoids forcing litellm import."""

model = self.name
if model in OPENAI_MODELS or model.startswith("openai/"):
if model.startswith(("gpt-", "openai/")):
var = "OPENAI_API_KEY"
elif model in ANTHROPIC_MODELS or model.startswith("anthropic/"):
elif model.startswith(("claude-", "anthropic/")):
var = "ANTHROPIC_API_KEY"
else:
return
Expand Down

0 comments on commit 551d357

Please sign in to comment.