Spaces:
Running
Running
File size: 3,536 Bytes
0157ac7 43ea069 55f294b 98fdd46 0157ac7 43ea069 98fdd46 0157ac7 db83b53 0157ac7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | """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"
@dataclass(frozen=True, slots=True)
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")
|