Skip to main content

ModelProvider

Trait ModelProvider 

Source
pub trait ModelProvider: Send + Sync {
    // Required method
    fn stream(&self, request: ModelRequest) -> ModelStream;

    // Provided methods
    fn complete<'life0, 'async_trait>(
        &'life0 self,
        request: ModelRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ModelResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn list_models<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for model provider backends that can stream and complete requests.

Implementors handle the wire protocol for a specific API (OpenAI, Anthropic, Gemini, etc.) while the engine works with the generic ModelRequest and ModelStreamEvent types.

Required Methods§

Source

fn stream(&self, request: ModelRequest) -> ModelStream

Starts a streaming request and returns a stream of ModelStreamEvent.

Provided Methods§

Source

fn complete<'life0, 'async_trait>( &'life0 self, request: ModelRequest, ) -> Pin<Box<dyn Future<Output = Result<ModelResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Completes a request by consuming the full stream and returning the accumulated text response. Default implementation calls Self::stream.

Source

fn list_models<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists available model identifiers from this provider.

Returns an error if the provider does not support model listing.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§