Skip to main content

BaseChatModel

Trait BaseChatModel 

Source
pub trait BaseChatModel: Send + Sync {
    // Required methods
    fn invoke<'a>(
        &'a self,
        messages: &'a [Message],
        config: Option<&'a RunnableConfig>,
    ) -> BoxFuture<'a, Result<ChatResult, SynwireError>>;
    fn stream<'a>(
        &'a self,
        messages: &'a [Message],
        config: Option<&'a RunnableConfig>,
    ) -> BoxFuture<'a, Result<BoxStream<'a, Result<ChatChunk, SynwireError>>, SynwireError>>;
    fn model_type(&self) -> &str;

    // Provided methods
    fn batch<'a>(
        &'a self,
        inputs: &'a [Vec<Message>],
        config: Option<&'a RunnableConfig>,
    ) -> BoxFuture<'a, Result<Vec<ChatResult>, SynwireError>> { ... }
    fn bind_tools(
        &self,
        _tools: &[ToolSchema],
    ) -> Result<Box<dyn BaseChatModel>, SynwireError> { ... }
}
Expand description

Base trait for chat language models.

All chat models must implement this trait. Methods use manual BoxFuture desugaring for dyn-compatibility.

§Cancel safety

The futures returned by invoke, batch, and stream are not cancel-safe in general. Dropping a future mid-execution may leave the underlying HTTP connection in an indeterminate state. If you need cancellation, use tokio::time::timeout and create a fresh request on timeout. The BoxStream returned by stream can be safely dropped at any point; unread chunks are simply discarded.

Required Methods§

Source

fn invoke<'a>( &'a self, messages: &'a [Message], config: Option<&'a RunnableConfig>, ) -> BoxFuture<'a, Result<ChatResult, SynwireError>>

Invoke the model with a list of messages.

Source

fn stream<'a>( &'a self, messages: &'a [Message], config: Option<&'a RunnableConfig>, ) -> BoxFuture<'a, Result<BoxStream<'a, Result<ChatChunk, SynwireError>>, SynwireError>>

Stream model responses as incremental chunks.

Source

fn model_type(&self) -> &str

Returns the model type identifier.

Provided Methods§

Source

fn batch<'a>( &'a self, inputs: &'a [Vec<Message>], config: Option<&'a RunnableConfig>, ) -> BoxFuture<'a, Result<Vec<ChatResult>, SynwireError>>

Invoke the model on multiple inputs concurrently.

Source

fn bind_tools( &self, _tools: &[ToolSchema], ) -> Result<Box<dyn BaseChatModel>, SynwireError>

Returns a new model instance with tools bound.

Implementors§