Skip to main content

Module ai

Module ai 

Source
Expand description

Build the AI subsystem (model registry + provider clients + cache + call log) from [ai] / [models] server configuration.

Secrets are resolved here, at startup: api_key_env names an environment variable, never the key itself. A provider’s transport is its kind (or, when omitted, inferred from the provider name): anthropic, local, or otherwise an OpenAI-compatible endpoint (openai, Azure, vLLM, …). A single local provider (its cache_dir) backs every local model; remote providers are keyed by name and matched to each remote model’s provider.

Constants§

CALL_LOG_CAPACITY 🔒
Retained laminar.ai_calls records.

Functions§

build_ai_runtime 🔒
Build the AI runtime from configuration, or None if no models are configured.
build_err 🔒
build_provider 🔒
Build one remote provider client. Returns None for the local backend (it is the runtime’s separate local_provider, not an entry in the providers map).
maybe_rate_limit 🔒
Pace a provider to requests_per_second when configured, else leave it as-is.
provider_kind 🔒
A provider’s transport kind: its explicit kind, else inferred from the name.
resolve_key 🔒
Resolve a provider’s API key from its api_key_env environment variable.