Skip to main content

LLMAdapter

Trait LLMAdapter 

Source
pub trait LLMAdapter: Send + Sync {
    // Required methods
    fn provider(&self) -> &str;
    fn model(&self) -> &str;
    fn generate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        messages: &'life1 [LLMMessage],
    ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn generate_stream(
        &self,
        messages: &[LLMMessage],
    ) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, LLMError>> + Send + '_>>;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<bool, LLMError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for LLM adapters.

Implement this trait to add support for a new LLM provider.

Required Methods§

Source

fn provider(&self) -> &str

Get the provider name (e.g., “openai”, “anthropic”).

Source

fn model(&self) -> &str

Get the model name being used.

Source

fn generate<'life0, 'life1, 'async_trait>( &'life0 self, messages: &'life1 [LLMMessage], ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generate a completion from messages.

§Errors

Returns an error if the API call fails.

Source

fn generate_stream( &self, messages: &[LLMMessage], ) -> Pin<Box<dyn Stream<Item = Result<StreamChunk, LLMError>> + Send + '_>>

Generate a streaming completion.

Returns a stream of chunks that can be processed as they arrive.

Source

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

Check if the LLM provider is accessible.

§Errors

Returns an error if the health check fails.

Implementors§