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§
Sourcefn 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,
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§
Sourcefn capabilities(&self) -> ModelCapabilities
fn capabilities(&self) -> ModelCapabilities
Get model capabilities
Sourcefn requires_network(&self) -> bool
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).
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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,
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.