ChatProvider

Trait ChatProvider 

Source
pub trait ChatProvider: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn chat<'life0, 'async_trait>(
        &'life0 self,
        request: ChatCompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, AiLibError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stream<'life0, 'async_trait>(
        &'life0 self,
        request: ChatCompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<ChatCompletionChunk, AiLibError>> + Send + Unpin>, AiLibError>> + 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>, AiLibError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_model_info<'life0, 'life1, 'async_trait>(
        &'life0 self,
        model_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<ModelInfo, AiLibError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn batch<'life0, 'async_trait>(
        &'life0 self,
        requests: Vec<ChatCompletionRequest>,
        concurrency_limit: Option<usize>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Result<ChatCompletionResponse, AiLibError>>, AiLibError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Unified chat provider trait exposed to the rest of the crate.

This supersedes the legacy ChatApi naming so that downstream consumers can implement a single trait (ChatProvider) whether they are composing routing strategies or writing bespoke adapters.

Required Methods§

Source

fn name(&self) -> &str

Human readable provider name (used in logs/metrics/strategies).

Source

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

Send chat completion request

§Arguments
  • request - Generic chat completion request
§Returns
  • Result<ChatCompletionResponse, AiLibError> - Returns response on success, error on failure
Source

fn stream<'life0, 'async_trait>( &'life0 self, request: ChatCompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<ChatCompletionChunk, AiLibError>> + Send + Unpin>, AiLibError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Streaming chat completion request

§Arguments
  • request - Generic chat completion request
§Returns
  • Result<impl Stream<Item = Result<ChatCompletionChunk, AiLibError>>, AiLibError> - Returns streaming response on success
Source

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

Get list of supported models

§Returns
  • Result<Vec<String>, AiLibError> - Returns model list on success, error on failure
Source

fn get_model_info<'life0, 'life1, 'async_trait>( &'life0 self, model_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ModelInfo, AiLibError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get model information

§Arguments
  • model_id - Model ID
§Returns
  • Result<ModelInfo, AiLibError> - Returns model information on success, error on failure

Provided Methods§

Source

fn batch<'life0, 'async_trait>( &'life0 self, requests: Vec<ChatCompletionRequest>, concurrency_limit: Option<usize>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Result<ChatCompletionResponse, AiLibError>>, AiLibError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Batch chat completion requests

§Arguments
  • requests - Vector of chat completion requests
  • concurrency_limit - Optional concurrency limit for concurrent processing
§Returns
  • Result<Vec<Result<ChatCompletionResponse, AiLibError>>, AiLibError> - Returns vector of results

Implementors§