Skip to main content

ModelFactory

Trait ModelFactory 

Source
pub trait ModelFactory: Send + Sync {
    // Required methods
    fn api_type(&self) -> &str;
    fn build(
        &self,
        provider_id: &str,
        config: &ProviderConfig,
        credentials: &dyn CredentialSource,
        network: Option<&Arc<dyn Network>>,
    ) -> Result<Arc<dyn Model>, String>;
}
Expand description

Builds a live model from one provider’s configuration.

Required Methods§

Source

fn api_type(&self) -> &str

The api value in settings.json this factory answers to.

Source

fn build( &self, provider_id: &str, config: &ProviderConfig, credentials: &dyn CredentialSource, network: Option<&Arc<dyn Network>>, ) -> Result<Arc<dyn Model>, String>

Construct the model, or say what is wrong with the config.

provider_id is only for the error message — it is the name the user wrote, and an error that does not name it makes them guess which of their providers is broken.

The credential comes from credentials, never from config.api_key_env directly: a factory that reads the field itself silently opts its protocol out of whatever the host arranged, which is exactly the bug the source exists to prevent.

network, when there is one, is the egress the model’s requests go out on — it carries the deployment’s User-Agent; None leaves the factory’s own.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§