Skip to main content

AsyncLanguageModel

Trait AsyncLanguageModel 

Source
pub trait AsyncLanguageModel: Send + Sync {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn complete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn complete_with_params<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
        params: GenerationParams,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn is_available<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn model_info<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ModelInfo> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn complete_batch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        prompts: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn complete_batch_concurrent<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        prompts: &'life1 [&'life2 str],
        max_concurrent: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn complete_streaming<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String>> + Send>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: '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 { ... }
    fn get_usage_stats<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<ModelUsageStats>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn estimate_tokens<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Async Large Language Model abstraction for non-blocking text generation

§Async Version

This trait provides async operations for text generation with better throughput and concurrency.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The error type returned by generation operations

Required Methods§

Source

fn complete<'life0, 'life1, 'async_trait>( &'life0 self, prompt: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate text completion

Source

fn complete_with_params<'life0, 'life1, 'async_trait>( &'life0 self, prompt: &'life1 str, params: GenerationParams, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate text with custom parameters

Source

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

Check if the model is available

Source

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

Get model information

Provided Methods§

Source

fn complete_batch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prompts: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Generate multiple text completions concurrently

Source

fn complete_batch_concurrent<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prompts: &'life1 [&'life2 str], max_concurrent: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Generate multiple text completions with concurrency control

Source

fn complete_streaming<'life0, 'life1, 'async_trait>( &'life0 self, prompt: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String>> + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate streaming completion (if supported)

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,

Health check for language model service

Source

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

Get model usage statistics

Source

fn estimate_tokens<'life0, 'life1, 'async_trait>( &'life0 self, prompt: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Estimate tokens for prompt

Implementors§