Spaces:
Running
Running
| """Neutral provider catalog: IDs, credentials, defaults, proxy and capability metadata. | |
| Adapter factories live in :mod:`providers.registry`; this module stays free of | |
| provider implementation imports (see contract tests). | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import Literal | |
| TransportType = Literal["openai_chat", "anthropic_messages"] | |
| # Default upstream base URLs (also re-exported via :mod:`providers.defaults`) | |
| NVIDIA_NIM_DEFAULT_BASE = "https://integrate.api.nvidia.com/v1" | |
| ZEN_DEFAULT_BASE = "https://opencode.ai/zen" | |
| CEREBRAS_DEFAULT_BASE = "https://api.cerebras.ai/v1" | |
| SILICON_DEFAULT_BASE = "https://api.siliconflow.com/v1" | |
| GROQ_DEFAULT_BASE = "https://api.groq.com/openai/v1" | |
| class ProviderDescriptor: | |
| """Metadata for building :class:`~providers.base.ProviderConfig` and factory wiring.""" | |
| provider_id: str | |
| transport_type: TransportType | |
| capabilities: tuple[str, ...] | |
| credential_env: str | None = None | |
| credential_url: str | None = None | |
| credential_attr: str | None = None | |
| static_credential: str | None = None | |
| default_base_url: str | None = None | |
| base_url_attr: str | None = None | |
| proxy_attr: str | None = None | |
| PROVIDER_CATALOG: dict[str, ProviderDescriptor] = { | |
| "nvidia_nim": ProviderDescriptor( | |
| provider_id="nvidia_nim", | |
| transport_type="openai_chat", | |
| credential_env="NVIDIA_NIM_API_KEY_QWEN", | |
| credential_url="https://build.nvidia.com/settings/api-keys", | |
| credential_attr="nvidia_nim_api_key_qwen", | |
| default_base_url=NVIDIA_NIM_DEFAULT_BASE, | |
| proxy_attr="nvidia_nim_proxy", | |
| capabilities=("chat", "streaming", "tools", "thinking", "rate_limit"), | |
| ), | |
| "zen": ProviderDescriptor( | |
| provider_id="zen", | |
| transport_type="openai_chat", | |
| credential_env="ZEN_API_KEY", | |
| credential_url="https://opencode.ai/settings", | |
| credential_attr="zen_api_key", | |
| default_base_url=ZEN_DEFAULT_BASE, | |
| base_url_attr="zen_base_url", | |
| capabilities=("chat", "streaming", "tools", "thinking"), | |
| ), | |
| "cerebras": ProviderDescriptor( | |
| provider_id="cerebras", | |
| transport_type="openai_chat", | |
| credential_env="CEREBRAS_API_KEY", | |
| credential_url="https://cerebras.ai/labs", | |
| credential_attr="cerebras_api_key", | |
| default_base_url=CEREBRAS_DEFAULT_BASE, | |
| capabilities=("chat", "streaming", "tools", "thinking"), | |
| ), | |
| "silicon": ProviderDescriptor( | |
| provider_id="silicon", | |
| transport_type="openai_chat", | |
| credential_env="SILICON_API_KEY", | |
| credential_url="https://siliconflow.cn", | |
| credential_attr="silicon_api_key", | |
| default_base_url=SILICON_DEFAULT_BASE, | |
| capabilities=("chat", "streaming", "tools", "thinking"), | |
| ), | |
| "groq": ProviderDescriptor( | |
| provider_id="groq", | |
| transport_type="openai_chat", | |
| credential_env="GROQ_API_KEY", | |
| credential_url="https://console.groq.com/keys", | |
| credential_attr="groq_api_key", | |
| default_base_url=GROQ_DEFAULT_BASE, | |
| capabilities=("chat", "streaming", "tools", "thinking"), | |
| ), | |
| } | |
| # Order matches docs; must match PROVIDER_CATALOG keys. | |
| SUPPORTED_PROVIDER_IDS: tuple[str, ...] = ( | |
| "nvidia_nim", | |
| "zen", | |
| "cerebras", | |
| "silicon", | |
| "groq", | |
| ) | |
| if len(set(SUPPORTED_PROVIDER_IDS)) != len(SUPPORTED_PROVIDER_IDS): | |
| raise AssertionError("Duplicate provider ids in PROVIDER_CATALOG key order") | |