ChatApi

Trait ChatApi 

Source
pub trait ChatApi: Send + Sync {
    // Required methods
    fn chat_completion<'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 chat_completion_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;
}
Expand description

通用的聊天API接口,定义所有AI服务的核心能力

Generic chat API interface

This trait defines the core capabilities that all AI services should have, without depending on any specific model implementation details

Required Methods§

Source

fn chat_completion<'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 chat_completion_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

Implementors§