pub trait ChatModel:
Send
+ Sync
+ Clone
+ 'static {
// Required methods
fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: Option<&'life2 CallOptions>,
) -> Pin<Box<dyn Future<Output = Result<Message, LlmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: Option<&'life2 CallOptions>,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'_, Result<MessageChunk, LlmError>>, LlmError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn bind_tools(&self, tools: Vec<ToolDefinition>) -> Self;
fn with_structured_output<T: JsonSchema + DeserializeOwned + Serialize>(
self,
) -> StructuredOutputModel<Self, T>
where Self: Sized;
fn model_name(&self) -> &str;
}Expand description
Unified ChatModel trait for all LLM providers
This trait provides a common interface for interacting with different
LLM providers (Anthropic, OpenAI, Ollama, etc.).
§Type Parameters
'a- Lifetime for borrowed data in streaming
Required Methods§
Sourcefn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: Option<&'life2 CallOptions>,
) -> Pin<Box<dyn Future<Output = Result<Message, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn invoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: Option<&'life2 CallOptions>,
) -> Pin<Box<dyn Future<Output = Result<Message, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: Option<&'life2 CallOptions>,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'_, Result<MessageChunk, LlmError>>, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: Option<&'life2 CallOptions>,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'_, Result<MessageChunk, LlmError>>, LlmError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn bind_tools(&self, tools: Vec<ToolDefinition>) -> Self
fn bind_tools(&self, tools: Vec<ToolDefinition>) -> Self
Bind tools to this model instance
Returns a new instance with the tools registered for function calling.
§Arguments
tools- List of tool definitions
Sourcefn with_structured_output<T: JsonSchema + DeserializeOwned + Serialize>(
self,
) -> StructuredOutputModel<Self, T>where
Self: Sized,
fn with_structured_output<T: JsonSchema + DeserializeOwned + Serialize>(
self,
) -> StructuredOutputModel<Self, T>where
Self: Sized,
Convert to structured output model
Returns a wrapper that forces the model to output structured JSON matching type T’s schema.
§Type Parameters
T- Target type with JSON Schema support
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".