Skip to main content

AiProvider

Trait AiProvider 

Source
pub trait AiProvider: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn generate<'life0, 'async_trait>(
        &'life0 self,
        request: GenerationRequest,
    ) -> Pin<Box<dyn Future<Output = Result<GenerationResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn generate_stream(
        &self,
        _request: GenerationRequest,
    ) -> BoxStream<'static, Result<StreamResponse>> { ... }
    fn generate_batch<'life0, 'async_trait>(
        &'life0 self,
        requests: Vec<GenerationRequest>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<GenerationResponse>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait that AI providers must implement.

This trait defines the interface for generating code from slots.

Required Methods§

Source

fn name(&self) -> &str

Get the provider name.

Source

fn generate<'life0, 'async_trait>( &'life0 self, request: GenerationRequest, ) -> Pin<Box<dyn Future<Output = Result<GenerationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate code for a slot.

§Arguments
  • request - The generation request containing slot info
§Returns

Generated code response or an error.

Provided Methods§

Source

fn generate_stream( &self, _request: GenerationRequest, ) -> BoxStream<'static, Result<StreamResponse>>

Generate a stream of code for a slot.

§Arguments
  • request - The generation request containing slot info
§Returns

A pinned stream of chunks or an error.

Source

fn generate_batch<'life0, 'async_trait>( &'life0 self, requests: Vec<GenerationRequest>, ) -> Pin<Box<dyn Future<Output = Result<Vec<GenerationResponse>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate code for multiple slots in batch.

Default implementation calls generate for each slot sequentially.

Source

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

Check if the provider is available and configured correctly.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: AiProvider + ?Sized + Send + Sync> AiProvider for Arc<T>

Source§

fn name(&self) -> &str

Source§

fn generate<'life0, 'async_trait>( &'life0 self, request: GenerationRequest, ) -> Pin<Box<dyn Future<Output = Result<GenerationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn generate_stream( &self, request: GenerationRequest, ) -> BoxStream<'static, Result<StreamResponse>>

Source§

impl<T: AiProvider + ?Sized + Send + Sync> AiProvider for Box<T>

Source§

fn name(&self) -> &str

Source§

fn generate<'life0, 'async_trait>( &'life0 self, request: GenerationRequest, ) -> Pin<Box<dyn Future<Output = Result<GenerationResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn generate_stream( &self, request: GenerationRequest, ) -> BoxStream<'static, Result<StreamResponse>>

Implementors§