Skip to main content

Module factory

Module factory 

Source
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(), .with_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
Per-family construction trait. Implemented (directly or via the CompatFamilySpec blanket) by every typed <Family>ModelProviderConfig.

Functions§

apply_compat_options
Apply cross-cutting compat post-processing (timeout, headers, api_path, max_tokens, reasoning effort) to a freshly-constructed compat provider and box it for trait-object dispatch. Single source of the post-process chain — every compat impl funnels through here.
dispatch_family_factory
Dispatch family construction by routing (family, alias) to the typed slot’s FamilyProviderFactory impl. Generated from for_each_model_provider_slot! so the family list lives in exactly one place — adding a row to the slot macro requires a corresponding impl, caught at compile time when the macro expands.