Skip to main content

ModelProvider

Trait ModelProvider 

Source
pub trait ModelProvider: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn chat<'life0, 'async_trait>(
        &'life0 self,
        request: ChatRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn model(&self) -> &str { ... }
    fn capabilities(&self) -> ModelCapabilities { ... }
    fn requires_network(&self) -> bool { ... }
    fn embed<'life0, 'async_trait>(
        &'life0 self,
        _request: EmbeddingRequest,
    ) -> Pin<Box<dyn Future<Output = Result<EmbeddingResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn generate_image<'life0, 'async_trait>(
        &'life0 self,
        _request: ImageGenerationRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ImageGenerationResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn transcribe<'life0, 'async_trait>(
        &'life0 self,
        _request: AudioTranscriptionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<AudioTranscriptionResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn speak<'life0, 'async_trait>(
        &'life0 self,
        _request: SpeechRequest,
    ) -> Pin<Box<dyn Future<Output = Result<SpeechResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn generate_video<'life0, 'async_trait>(
        &'life0 self,
        _request: VideoGenerationRequest,
    ) -> Pin<Box<dyn Future<Output = Result<VideoGenerationResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Model provider trait

Required Methods§

Source

fn name(&self) -> &str

Provider name

Source

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

Create a chat completion

Provided Methods§

Source

fn model(&self) -> &str

Model name being used

Source

fn capabilities(&self) -> ModelCapabilities

Get model capabilities

Source

fn requires_network(&self) -> bool

Whether this provider requires network access. Default is true for cloud LLM providers. Override to false for local providers (e.g., Ollama).

Source

fn embed<'life0, 'async_trait>( &'life0 self, _request: EmbeddingRequest, ) -> Pin<Box<dyn Future<Output = Result<EmbeddingResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate embeddings (if supported)

Default implementation returns an error. Providers that support embeddings should override this method.

Source

fn generate_image<'life0, 'async_trait>( &'life0 self, _request: ImageGenerationRequest, ) -> Pin<Box<dyn Future<Output = Result<ImageGenerationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate images (if supported)

Default implementation returns an error. Providers that support image generation (e.g., DALL-E, Flux, Stable Diffusion) should override this method.

Source

fn transcribe<'life0, 'async_trait>( &'life0 self, _request: AudioTranscriptionRequest, ) -> Pin<Box<dyn Future<Output = Result<AudioTranscriptionResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Transcribe audio to text (if supported)

Default implementation returns an error. Providers that support audio transcription (e.g., Whisper) should override this method.

Source

fn speak<'life0, 'async_trait>( &'life0 self, _request: SpeechRequest, ) -> Pin<Box<dyn Future<Output = Result<SpeechResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate speech from text (if supported)

Default implementation returns an error. Providers that support text-to-speech should override this method.

Source

fn generate_video<'life0, 'async_trait>( &'life0 self, _request: VideoGenerationRequest, ) -> Pin<Box<dyn Future<Output = Result<VideoGenerationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate video (if supported)

Default implementation returns an error. Providers that support video generation (e.g., Runway, Pika) should override this method.

Implementors§