hsliuping/TradingAgents-CN · error · ValueError
不支持的OpenAI兼容提供商: {provider}
Error message
不支持的OpenAI兼容提供商: {provider} What it means
create_openai_compatible_llm is a factory that only accepts providers registered in the OPENAI_COMPATIBLE_PROVIDERS registry; an unregistered name raises this immediately. The registry maps provider slugs to adapter classes and optional default base URLs, so unknown slugs cannot be dispatched. This is a typo/registration error, not a runtime environment issue.
Source
Thrown at tradingagents/llm_adapters/openai_compatible_base.py:512
"custom-model": {"context_length": 32768, "supports_function_calling": True}
}
}
}
def create_openai_compatible_llm(
provider: str,
model: str,
api_key: Optional[str] = None,
temperature: float = 0.1,
max_tokens: Optional[int] = None,
base_url: Optional[str] = None,
**kwargs
) -> OpenAICompatibleBase:
"""创建OpenAI兼容LLM实例的统一工厂函数"""
provider_info = OPENAI_COMPATIBLE_PROVIDERS.get(provider)
if not provider_info:
raise ValueError(f"不支持的OpenAI兼容提供商: {provider}")
adapter_class = provider_info["adapter_class"]
# 如果调用未提供 base_url,则采用 provider 的默认值(可能为 None)
if base_url is None:
base_url = provider_info.get("base_url")
# 仅当 provider 未内置 base_url(如 custom_openai)时,才将 base_url 传递给适配器,
# 避免与适配器内部的 super().__init__(..., base_url=...) 冲突导致 "multiple values" 错误。
init_kwargs = dict(
model=model,
api_key=api_key,
temperature=temperature,
max_tokens=max_tokens,
**kwargs,
)
if provider_info.get("base_url") is None and base_url:
init_kwargs["base_url"] = base_urlView on GitHub (pinned to 74783e8817)
Solutions
- Check valid slugs via list(OPENAI_COMPATIBLE_PROVIDERS) in openai_compatible_base.py and use an exact match (lowercase)
- Register your custom adapter: OPENAI_COMPATIBLE_PROVIDERS['myprov'] = {'adapter_class': MyProvAdapter, 'base_url': '...'}
- Normalize/validate provider strings from config or UI before calling the factory
Example fix
# before llm = create_openai_compatible_llm(provider="DeepSeek", model="deepseek-chat") # case mismatch # after llm = create_openai_compatible_llm(provider="deepseek", model="deepseek-chat") # exact registry slug
Defensive patterns
Strategy: type-guard
Validate before calling
from tradingagents.llm_adapters.openai_compatible_base import OPENAI_COMPATIBLE_PROVIDERS
provider = provider.strip().lower()
if provider not in OPENAI_COMPATIBLE_PROVIDERS:
raise SystemExit(f"Unknown provider '{provider}'. Valid: {sorted(OPENAI_COMPATIBLE_PROVIDERS)}") Type guard
def is_supported_provider(provider: str) -> bool:
from tradingagents.llm_adapters.openai_compatible_base import OPENAI_COMPATIBLE_PROVIDERS
return provider.strip().lower() in OPENAI_COMPATIBLE_PROVIDERS Try / catch
try:
llm = create_openai_compatible_llm(provider=p, model=m)
except ValueError as e:
if "不支持的OpenAI兼容提供商" in str(e):
raise SystemExit(f"Unknown provider '{p}'; check registry") from e
raise Prevention
- Normalize provider strings (strip + lower) at config boundaries
- Constrain UI/provider dropdowns to registry keys
- Register new adapters in OPENAI_COMPATIBLE_PROVIDERS as part of the adapter checklist
When it happens
Trigger: Calling create_openai_compatible_llm(provider="openai") or any slug not in OPENAI_COMPATIBLE_PROVIDERS (e.g. 'gpt', 'azure', 'googl'), or a custom provider that was never registered.
Common situations: Provider string from user input or config passed unsanitized; provider slug renamed between versions; new adapter written but not added to the registry dict; case mismatch ('DeepSeek' vs 'deepseek').
Related errors
- Indicator {indicator} is not supported. Please choose from:
- REDDIT FETCHING ERROR: max limit is less than the number of
- Trading Agents Graph Setup Error: no analysts selected!
- QIANFAN_API_KEY格式错误,应为: bce-v3/ALTAK-xxx/xxx
- Unsupported LLM provider: {provider}
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/9b16eed1da732502.
Report an issue: GitHub.