Skip to main content

LLMClient

Trait LLMClient 

Source
pub trait LLMClient: Send + Sync {
    // Required methods
    fn generate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<String, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn generate_with_system<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        system: &'life1 str,
        prompt: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<String, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn generate_with_history<'life0, 'life1, 'async_trait>(
        &'life0 self,
        messages: &'life1 [(String, String)],
    ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn generate_with_tools<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
        tools: &'life2 [ToolDefinition],
    ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn generate_with_tools_and_history<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [ConversationMessage],
        tools: &'life2 [ToolDefinition],
    ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn stream<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<String, AppError>> + Send + Unpin>, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn stream_with_system<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        system: &'life1 str,
        prompt: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<String, AppError>> + Send + Unpin>, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn stream_with_history<'life0, 'life1, 'async_trait>(
        &'life0 self,
        messages: &'life1 [(String, String)],
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<String, AppError>> + Send + Unpin>, AppError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn model_name(&self) -> &str;

    // Provided methods
    fn supports_hints(&self) -> bool { ... }
    fn set_hints(&self, _hints: GenerationHints) { ... }
}
Expand description

Generic LLM client trait for provider abstraction

Required Methods§

Source

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

Generate a completion from a prompt

Source

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

Generate with system prompt

Source

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

Generate with conversation history, returning full response with token usage

Source

fn generate_with_tools<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prompt: &'life1 str, tools: &'life2 [ToolDefinition], ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Generate with tool calling support

Source

fn generate_with_tools_and_history<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [ConversationMessage], tools: &'life2 [ToolDefinition], ) -> Pin<Box<dyn Future<Output = Result<LLMResponse, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Generate with conversation history AND tool definitions.

This is the core method for multi-turn tool calling, combining:

  • generate_with_history() - conversation context
  • generate_with_tools() - tool calling capability
§Arguments
  • messages - Conversation history as ConversationMessage structs
  • tools - Available tool definitions
§Returns

An LLMResponse containing the model’s reply and any tool calls requested.

Source

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

Stream a completion

Source

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

Stream a completion with system prompt

Source

fn stream_with_history<'life0, 'life1, 'async_trait>( &'life0 self, messages: &'life1 [(String, String)], ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Stream<Item = Result<String, AppError>> + Send + Unpin>, AppError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Stream a completion with conversation history

Source

fn model_name(&self) -> &str

Get the model name/identifier

Provided Methods§

Source

fn supports_hints(&self) -> bool

Whether this client honors GenerationHints set via LLMClient::set_hints. Defaults to false; hint-aware providers override this together with set_hints.

Source

fn set_hints(&self, _hints: GenerationHints)

Store generation hints applying to SUBSEQUENT generate calls, until replaced (clear with GenerationHints::default()). Default impl is a no-op so unmodified providers keep compiling unchanged. Implementers MUST use interior mutability; see GenerationHints for thread-safety expectations and provider mapping guidance.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§