Skip to main content

Module factory

Module factory 

Expand description

Per-family construction dispatch for model providers.

Each <Family>ModelProviderConfig typed slot from zeroclaw-config::providers::ModelProviders declares its own construction via one of two traits:

  • CompatFamilySpec for OpenAI-compatible families. Declare DISPLAY / DEFAULT_URL / AUTH; the blanket impl<T: CompatFamilySpec> FamilyProviderFactory for T produces the provider. Families with minor modifiers (.without_native_tools(), .models_dev_key(...), multi-endpoint URI fallback) override build_compat — still one place per family, no flat dispatch arm.

  • FamilyProviderFactory directly for bespoke families that wrap a non-compat runtime provider (azure, gemini, openrouter, bedrock, anthropic, …).

Dispatch is generated by for_each_model_provider_slot! — the same macro that defines the typed slots is the only place the family list lives. Adding a family is one slot row plus one trait impl; missing the impl fails to compile when the dispatch is generated.

Traits§

CompatFamilySpec
Spec trait for OpenAI-compatible families. Implementing this gives a FamilyProviderFactory impl for free via the blanket below.
FamilyProviderFactory

Functions§

apply_compat_options
Apply cross-cutting compat overrides (timeout, headers, api_path, max_tokens, reasoning effort, TLS CA, provider_extra) to a compat builder before calling .build() and boxing the trait object. Single source of the override chain — every compat impl funnels through here.
dispatch_family_factory
get_default_url
Get the default API URL for a provider type (matches CompatFamilySpec::DEFAULT_URL). Returns None if the provider type is not an OpenAI-compatible family with a DEFAULT_URL const.