pub trait BaseChatModel: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn invoke(
&self,
messages: &[Message],
config: &RunnableConfig,
) -> Result<Message, ModelError>;
fn bind_tools(&self, tools: Vec<ToolDef>) -> Box<dyn BaseChatModel>;
// Provided methods
fn ainvoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
config: &'life2 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn astream<'a>(
&'a self,
messages: &'a [Message],
config: &'a RunnableConfig,
) -> MessageStream<'a> { ... }
}Expand description
A chat model that can generate responses.
Mirrors langchain-core’s BaseChatModel.
Required Methods§
Sourcefn invoke(
&self,
messages: &[Message],
config: &RunnableConfig,
) -> Result<Message, ModelError>
fn invoke( &self, messages: &[Message], config: &RunnableConfig, ) -> Result<Message, ModelError>
Invoke the model with a list of messages and get a response.
Sourcefn bind_tools(&self, tools: Vec<ToolDef>) -> Box<dyn BaseChatModel>
fn bind_tools(&self, tools: Vec<ToolDef>) -> Box<dyn BaseChatModel>
Bind tools to the model for tool-calling support.
Provided Methods§
Sourcefn ainvoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
config: &'life2 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn ainvoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
config: &'life2 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Invoke the model asynchronously. Default delegates to sync invoke via block_in_place.
Sourcefn astream<'a>(
&'a self,
messages: &'a [Message],
config: &'a RunnableConfig,
) -> MessageStream<'a>
fn astream<'a>( &'a self, messages: &'a [Message], config: &'a RunnableConfig, ) -> MessageStream<'a>
Stream tokens from the model. Returns a stream of partial Message chunks.
Each yielded Message represents the accumulated content up to that point.
For example, if the model generates “Hello world”, the stream might yield:
Message::ai("Hello")Message::ai("Hello world")
The final item in the stream is the complete response (including tool calls if any).
Default implementation falls back to ainvoke (yields a single complete message).
Trait Implementations§
Source§impl BaseChatModel for Box<dyn BaseChatModel>
impl BaseChatModel for Box<dyn BaseChatModel>
Source§fn invoke(
&self,
messages: &[Message],
config: &RunnableConfig,
) -> Result<Message, ModelError>
fn invoke( &self, messages: &[Message], config: &RunnableConfig, ) -> Result<Message, ModelError>
Source§fn ainvoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
config: &'life2 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn ainvoke<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
config: &'life2 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn astream<'a>(
&'a self,
messages: &'a [Message],
config: &'a RunnableConfig,
) -> MessageStream<'a>
fn astream<'a>( &'a self, messages: &'a [Message], config: &'a RunnableConfig, ) -> MessageStream<'a>
Source§fn bind_tools(&self, tools: Vec<ToolDef>) -> Box<dyn BaseChatModel>
fn bind_tools(&self, tools: Vec<ToolDef>) -> Box<dyn BaseChatModel>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".