Clear the deferred full-repo lint backlog so the whole tree passes the strict ruff select (E,W,F,I,B,UP,C4,SIM). Mechanical fixes dominate: import sorting, pep585/604 annotations, dropped dead imports, and whitespace. The few semantic changes are behavior-preserving: declare __all__ on the agent_utils and alpha_vantage re-export hubs; expand 'from x import *' to explicit names; use immutable tuple defaults instead of mutable list defaults; contextlib.suppress for try/except/pass; and narrow an over-broad assertRaises.
34 lines
963 B
Python
34 lines
963 B
Python
"""Model name validators for each provider."""
|
|
|
|
from .model_catalog import get_known_models
|
|
|
|
# Providers whose model names are user-defined (local servers, relays, hosted
|
|
# OpenAI-compatible endpoints serving many models), so any model string is
|
|
# accepted without warning.
|
|
_ANY_MODEL_PROVIDERS = (
|
|
"ollama", "openrouter", "openai_compatible",
|
|
"mistral", "kimi", "groq", "nvidia", "bedrock",
|
|
)
|
|
|
|
VALID_MODELS = {
|
|
provider: models
|
|
for provider, models in get_known_models().items()
|
|
if provider not in _ANY_MODEL_PROVIDERS
|
|
}
|
|
|
|
|
|
def validate_model(provider: str, model: str) -> bool:
|
|
"""Check if model name is valid for the given provider.
|
|
|
|
For ollama, openrouter, and openai_compatible - any model is accepted.
|
|
"""
|
|
provider_lower = provider.lower()
|
|
|
|
if provider_lower in _ANY_MODEL_PROVIDERS:
|
|
return True
|
|
|
|
if provider_lower not in VALID_MODELS:
|
|
return True
|
|
|
|
return model in VALID_MODELS[provider_lower]
|