pub struct ConversationChain<M: BaseChatModel> { /* private fields */ }Expand description
Conversation Chain
A Chain with memory that automatically saves and loads conversation history.
Implementations§
Source§impl<M: BaseChatModel + 'static> ConversationChain<M>
impl<M: BaseChatModel + 'static> ConversationChain<M>
Sourcepub fn new(llm: M, memory: ConversationBufferMemory) -> Self
pub fn new(llm: M, memory: ConversationBufferMemory) -> Self
Create a new ConversationChain.
§Arguments
llm- LLM client (any type implementing BaseChatModel)memory- Conversation memory
Sourcepub fn from_memory(llm: M, memory: Arc<Mutex<dyn BaseMemory>>) -> Self
pub fn from_memory(llm: M, memory: Arc<Mutex<dyn BaseMemory>>) -> Self
Create a ConversationChain from any BaseMemory implementation.
Unlike ConversationChain::new (which takes the concrete
ConversationBufferMemory), this accepts any memory — window, summary,
vector-store, persistent — so the chain’s memory is pluggable without
changing the chain source.
Sourcepub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
Set system prompt.
Sourcepub fn with_input_key(self, key: impl Into<String>) -> Self
pub fn with_input_key(self, key: impl Into<String>) -> Self
Set input key name.
Sourcepub fn with_output_key(self, key: impl Into<String>) -> Self
pub fn with_output_key(self, key: impl Into<String>) -> Self
Set output key name.
Sourcepub fn with_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Set verbose mode.
pub fn builder(llm: M) -> ConversationChainBuilder<M>
Sourcepub async fn clear_memory(&self) -> Result<(), ChainError>
pub async fn clear_memory(&self) -> Result<(), ChainError>
Clear memory.
Trait Implementations§
Source§impl<M: BaseChatModel + Send + Sync + 'static> BaseChain for ConversationChain<M>
impl<M: BaseChatModel + Send + Sync + 'static> BaseChain for ConversationChain<M>
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream execution for ConversationChain – token by token output.
Source§fn input_keys(&self) -> Vec<&str>
fn input_keys(&self) -> Vec<&str>
Get input keys.
Source§fn output_keys(&self) -> Vec<&str>
fn output_keys(&self) -> Vec<&str>
Get output keys.
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the Chain. Read more
Source§fn invoke_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the Chain with a RunnableConfig. Read more
Source§fn stream_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_with_config<'life0, 'async_trait>(
&'life0 self,
inputs: HashMap<String, Value>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<ChainStream, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream execute the Chain with a RunnableConfig. Read more
Source§fn validate_inputs(
&self,
inputs: &HashMap<String, Value>,
) -> Result<(), ChainError>
fn validate_inputs( &self, inputs: &HashMap<String, Value>, ) -> Result<(), ChainError>
Validate inputs.
Auto Trait Implementations§
impl<M> !RefUnwindSafe for ConversationChain<M>
impl<M> !UnwindSafe for ConversationChain<M>
impl<M> Freeze for ConversationChain<M>where
M: Freeze,
impl<M> Send for ConversationChain<M>
impl<M> Sync for ConversationChain<M>
impl<M> Unpin for ConversationChain<M>where
M: Unpin,
impl<M> UnsafeUnpin for ConversationChain<M>where
M: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more