pub trait Provider:
Send
+ Sync
+ Any {
// Required methods
fn name(&self) -> &str;
fn supports_streaming(&self) -> bool;
fn supports_function_calling(&self) -> bool;
fn supported_models(&self) -> Vec<String>;
fn chat_completion<'life0, 'async_trait>(
&'life0 self,
request: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stream_chat_completion<'life0, 'async_trait>(
&'life0 self,
request: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<StreamResult, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ProviderHealth, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn embedding<'life0, 'async_trait>(
&'life0 self,
_request: EmbeddingRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn image_generation<'life0, 'async_trait>(
&'life0 self,
_request: ImageRequest,
) -> Pin<Box<dyn Future<Output = Result<ImageResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn audio_transcription<'life0, 'async_trait>(
&'life0 self,
_request: AudioRequest,
) -> Pin<Box<dyn Future<Output = Result<AudioResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn text_to_speech<'life0, 'async_trait>(
&'life0 self,
_request: SpeechRequest,
) -> Pin<Box<dyn Future<Output = Result<SpeechResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Trait for AI/LLM provider implementations.
This trait defines the interface that all AI providers must implement, providing a unified API for different AI services.
§Examples
use ultrafast_models_sdk::providers::{Provider, ProviderConfig};
use ultrafast_models_sdk::models::{ChatRequest, ChatResponse};
use async_trait::async_trait;
struct MyProvider {
config: ProviderConfig,
}
#[async_trait]
impl Provider for MyProvider {
fn name(&self) -> &str { "my-provider" }
fn supports_streaming(&self) -> bool { true }
fn supports_function_calling(&self) -> bool { false }
fn supported_models(&self) -> Vec<String> { vec!["my-model".to_string()] }
async fn chat_completion(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
// Implementation here
todo!()
}
}Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Get the provider name/identifier.
Returns a unique identifier for this provider.
Sourcefn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Check if this provider supports streaming responses.
Returns true if the provider supports streaming chat completions.
Sourcefn supports_function_calling(&self) -> bool
fn supports_function_calling(&self) -> bool
Check if this provider supports function calling.
Returns true if the provider supports function calling and tool usage.
Sourcefn supported_models(&self) -> Vec<String>
fn supported_models(&self) -> Vec<String>
Get the list of models supported by this provider.
Returns a vector of model names that this provider can handle.