Files
TradingAgents/tradingagents/llm_clients/validators.py
T
Yijia-Xiao 895ed130f9 feat(llm): add Amazon Bedrock as a first-class provider
Bedrock uses the Converse API (langchain-aws) and the AWS credential chain, so
it has its own client like Anthropic/Google rather than the OpenAI-compatible
registry. langchain-aws is an optional dependency (pip install ".[bedrock]"),
lazy-imported with a clear install hint; importing the package never requires
it. The model name is a Bedrock model ID / inference profile ID.
2026-06-14 04:24:54 +00:00

35 lines
964 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]