Skip to main content

ModelProvider

Trait ModelProvider 

Source
pub trait ModelProvider:
    Debug
    + Send
    + Sync {
    // Required methods
    fn provider_id(&self) -> &ProviderId;
    fn models(&self) -> &[ModelSpec];
    fn stream(
        &self,
        request: ModelRequest,
        cancellation: ModelCancellation,
    ) -> BoxModelStream;

    // Provided method
    fn model(&self, model_id: &ModelId) -> Option<&ModelSpec> { ... }
}
Expand description

Object-safe provider-neutral model adapter port.

Request setup, transport, protocol, cancellation, and runtime failures must be emitted through the returned stream as terminal failure events. Provider implementations must not panic for expected failures or create a nested asynchronous runtime.

Required Methods§

Source

fn provider_id(&self) -> &ProviderId

Returns the stable adapter/provider identity.

Source

fn models(&self) -> &[ModelSpec]

Returns models advertised by this adapter in deterministic order.

Source

fn stream( &self, request: ModelRequest, cancellation: ModelCancellation, ) -> BoxModelStream

Creates a lazy normalized stream for one immutable request.

cancellation is cooperative. Completion must not be reported until resources owned directly by the stream have been cleaned up. Dropping the stream abandons it; implementations must therefore keep resource ownership inside the stream rather than a detached task.

Provided Methods§

Source

fn model(&self, model_id: &ModelId) -> Option<&ModelSpec>

Finds an advertised model by canonical ID.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§