diff --git a/server.py b/server.py index bf2ac6c1..7b54d5e6 100644 --- a/server.py +++ b/server.py @@ -122,6 +122,10 @@ def format(self, record): "gemini-2.5-pro" ] +def is_gemini_model(model_name: str) -> bool: + """Check if a model name is a Gemini model (known list or starts with 'gemini').""" + return model_name in GEMINI_MODELS or model_name.startswith("gemini") + # Helper function to clean schema for Gemini def clean_gemini_schema(schema: Any) -> Any: """Recursively removes unsupported fields from a JSON schema for Gemini.""" @@ -222,7 +226,7 @@ def validate_model_field(cls, v, info): # Renamed to avoid conflict # Map Haiku to SMALL_MODEL based on provider preference elif 'haiku' in clean_v.lower(): - if PREFERRED_PROVIDER == "google" and SMALL_MODEL in GEMINI_MODELS: + if PREFERRED_PROVIDER == "google" and is_gemini_model(SMALL_MODEL): new_model = f"gemini/{SMALL_MODEL}" mapped = True else: @@ -231,7 +235,7 @@ def validate_model_field(cls, v, info): # Renamed to avoid conflict # Map Sonnet to BIG_MODEL based on provider preference elif 'sonnet' in clean_v.lower(): - if PREFERRED_PROVIDER == "google" and BIG_MODEL in GEMINI_MODELS: + if PREFERRED_PROVIDER == "google" and is_gemini_model(BIG_MODEL): new_model = f"gemini/{BIG_MODEL}" mapped = True else: @@ -240,7 +244,7 @@ def validate_model_field(cls, v, info): # Renamed to avoid conflict # Add prefixes to non-mapped models if they match known lists elif not mapped: - if clean_v in GEMINI_MODELS and not v.startswith('gemini/'): + if is_gemini_model(clean_v) and not v.startswith('gemini/'): new_model = f"gemini/{clean_v}" mapped = True # Technically mapped to add prefix elif clean_v in OPENAI_MODELS and not v.startswith('openai/'): @@ -295,7 +299,7 @@ def validate_model_token_count(cls, v, info): # Renamed to avoid conflict mapped = False # Map Haiku to SMALL_MODEL based on provider preference if 'haiku' in clean_v.lower(): - if PREFERRED_PROVIDER == "google" and SMALL_MODEL in GEMINI_MODELS: + if PREFERRED_PROVIDER == "google" and is_gemini_model(SMALL_MODEL): new_model = f"gemini/{SMALL_MODEL}" mapped = True else: @@ -304,7 +308,7 @@ def validate_model_token_count(cls, v, info): # Renamed to avoid conflict # Map Sonnet to BIG_MODEL based on provider preference elif 'sonnet' in clean_v.lower(): - if PREFERRED_PROVIDER == "google" and BIG_MODEL in GEMINI_MODELS: + if PREFERRED_PROVIDER == "google" and is_gemini_model(BIG_MODEL): new_model = f"gemini/{BIG_MODEL}" mapped = True else: @@ -313,7 +317,7 @@ def validate_model_token_count(cls, v, info): # Renamed to avoid conflict # Add prefixes to non-mapped models if they match known lists elif not mapped: - if clean_v in GEMINI_MODELS and not v.startswith('gemini/'): + if is_gemini_model(clean_v) and not v.startswith('gemini/'): new_model = f"gemini/{clean_v}" mapped = True # Technically mapped to add prefix elif clean_v in OPENAI_MODELS and not v.startswith('openai/'):