Provider

Trait Provider 

Source
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§

Source

fn name(&self) -> &str

Get the provider name/identifier.

Returns a unique identifier for this provider.

Source

fn supports_streaming(&self) -> bool

Check if this provider supports streaming responses.

Returns true if the provider supports streaming chat completions.

Source

fn supports_function_calling(&self) -> bool

Check if this provider supports function calling.

Returns true if the provider supports function calling and tool usage.

Source

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.

Source

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,

Perform a chat completion request.

§Arguments
  • request - The chat completion request
§Returns

Returns a chat completion response or an error.

Source

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,

Perform a streaming chat completion request.

§Arguments
  • request - The chat completion request
§Returns

Returns a stream of chat completion chunks or an error.

Source

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,

Perform a health check on this provider.

§Returns

Returns provider health information or an error.

Provided Methods§

Source

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,

Generate embeddings for text input.

§Arguments
  • request - The embedding request
§Returns

Returns an embedding response or an error.

§Default Implementation

Returns a configuration error by default. Providers that support embeddings should override this method.

Source

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,

Generate images from text prompts.

§Arguments
  • request - The image generation request
§Returns

Returns an image generation response or an error.

§Default Implementation

Returns a configuration error by default. Providers that support image generation should override this method.

Source

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,

Transcribe audio to text.

§Arguments
  • request - The audio transcription request
§Returns

Returns an audio transcription response or an error.

§Default Implementation

Returns a configuration error by default. Providers that support audio transcription should override this method.

Source

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,

Convert text to speech.

§Arguments
  • request - The text-to-speech request
§Returns

Returns a speech response or an error.

§Default Implementation

Returns a configuration error by default. Providers that support text-to-speech should override this method.

Implementors§