Skip to main content

Provider

Trait Provider 

Source
pub trait Provider: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn list_models<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ModelInfo>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn complete<'life0, 'async_trait>(
        &'life0 self,
        request: CompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn complete_stream<'life0, 'async_trait>(
        &'life0 self,
        request: CompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, StreamChunk>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    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 { ... }
}
Expand description

Trait that all AI providers must implement.

Required Methods§

Source

fn name(&self) -> &str

Provider identifier (e.g. "openai", "bedrock").

§Examples
assert!(!p.name().is_empty());
Source

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

List models available under this provider.

§Examples
let models = p.list_models().await.unwrap();
assert!(!models.is_empty());
Source

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

Generate a single completion.

§Examples
let resp = p.complete(req).await.unwrap();
Source

fn complete_stream<'life0, 'async_trait>( &'life0 self, request: CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, StreamChunk>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate a streaming completion.

§Examples
let stream = p.complete_stream(req).await.unwrap();

Provided Methods§

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 (optional; default returns an error).

Implementors§