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§
Sourcefn 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<'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
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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<'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
Sourcefn 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 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 contextgenerate_with_tools()- tool calling capability
§Arguments
messages- Conversation history as ConversationMessage structstools- Available tool definitions
§Returns
An LLMResponse containing the model’s reply and any tool calls requested.
Sourcefn 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<'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
Sourcefn 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_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
Sourcefn 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 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
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name/identifier
Provided Methods§
Sourcefn supports_hints(&self) -> bool
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.
Sourcefn set_hints(&self, _hints: GenerationHints)
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".