"""Language-model providers."""
from __future__ import annotations
from ..config import LLMConfig
from .base import ChatMessage, LLMError, LLMProvider, extract_json
__all__ = ["ChatMessage", "LLMError", "LLMProvider", "build_provider", "extract_json"]
[docs]
def build_provider(cfg: LLMConfig) -> LLMProvider:
if cfg.provider in ("openai", "openai_compatible"):
if cfg.provider == "openai_compatible" and not cfg.base_url:
raise ValueError("llm.provider 'openai_compatible' requires llm.base_url")
from .openai_compat import OpenAICompatibleProvider
return OpenAICompatibleProvider(cfg)
if cfg.provider == "anthropic":
from .anthropic import AnthropicProvider
return AnthropicProvider(cfg)
if cfg.provider == "gemini":
from .gemini import GeminiProvider
return GeminiProvider(cfg)
raise ValueError(f"unknown llm.provider {cfg.provider!r}")