pub trait Provider:
Send
+ Sync
+ Debug
+ 'static {
// Required methods
fn info(&self) -> Arc<ProviderInfo>;
fn chat_completion<'life0, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, AiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stream_chat_completion<'life0, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<Box<ChatCompletionStream>, AiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Core provider trait for AI services.
This trait defines the simplified interface that all AI providers must implement. Providers only need to implement the basic chat completion API, and higher-level abstractions (generate_text, generate_object) are handled by the Runtime layer.
Required Methods§
Sourcefn info(&self) -> Arc<ProviderInfo>
fn info(&self) -> Arc<ProviderInfo>
Get provider information
Sourcefn chat_completion<'life0, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, AiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat_completion<'life0, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, AiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Chat completion (non-streaming)
This is the core method that all providers must implement. It handles a chat completion request and returns a response.
Sourcefn stream_chat_completion<'life0, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<Box<ChatCompletionStream>, AiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_chat_completion<'life0, 'async_trait>(
&'life0 self,
req: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<Box<ChatCompletionStream>, AiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream chat completion
Returns a stream of chat completion chunks for streaming responses.