pub struct ConversationBufferMemory { /* private fields */ }Expand description
Conversation Buffer Memory
Saves all conversation history in memory.
§Example
ⓘ
use lc_memory::ConversationBufferMemory;
let mut memory = ConversationBufferMemory::new();
// Save conversation
let inputs = HashMap::from([("input".to_string(), "Hello".to_string())]);
let outputs = HashMap::from([("output".to_string(), "Hi!".to_string())]);
memory.save_context(&inputs, &outputs).await?;
// Load memory
let memory_vars = memory.load_memory_variables(&HashMap::new()).await?;
println!("{:?}", memory_vars.get("history"));Implementations§
Source§impl ConversationBufferMemory
impl ConversationBufferMemory
Sourcepub fn with_input_key(self, key: String) -> Self
pub fn with_input_key(self, key: String) -> Self
Set input key name
Sourcepub fn with_output_key(self, key: String) -> Self
pub fn with_output_key(self, key: String) -> Self
Set output key name
Sourcepub fn with_memory_key(self, key: String) -> Self
pub fn with_memory_key(self, key: String) -> Self
Set memory variable name
Sourcepub fn with_return_messages(self, return_messages: bool) -> Self
pub fn with_return_messages(self, return_messages: bool) -> Self
Set whether to return message objects
Sourcepub fn from_chat_memory(chat_memory: ChatMessageHistory) -> Self
pub fn from_chat_memory(chat_memory: ChatMessageHistory) -> Self
Create from existing history
Sourcepub fn chat_memory(&self) -> &ChatMessageHistory
pub fn chat_memory(&self) -> &ChatMessageHistory
Get chat history
Sourcepub fn chat_memory_mut(&mut self) -> &mut ChatMessageHistory
pub fn chat_memory_mut(&mut self) -> &mut ChatMessageHistory
Get mutable chat history
Trait Implementations§
Source§impl BaseChatMemory for ConversationBufferMemory
P0-1: ConversationBufferMemory 实现 BaseChatMemory,可当聊天缓冲用。
impl BaseChatMemory for ConversationBufferMemory
P0-1: ConversationBufferMemory 实现 BaseChatMemory,可当聊天缓冲用。
Source§impl BaseMemory for ConversationBufferMemory
impl BaseMemory for ConversationBufferMemory
Source§fn load_memory_variables<'life0, 'life1, 'async_trait>(
&'life0 self,
_inputs: &'life1 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_memory_variables<'life0, 'life1, 'async_trait>(
&'life0 self,
_inputs: &'life1 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Load memory variables Read more
Source§fn save_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
inputs: &'life1 HashMap<String, String>,
outputs: &'life2 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn save_context<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
inputs: &'life1 HashMap<String, String>,
outputs: &'life2 HashMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Save context Read more
Source§impl Debug for ConversationBufferMemory
impl Debug for ConversationBufferMemory
Auto Trait Implementations§
impl Freeze for ConversationBufferMemory
impl RefUnwindSafe for ConversationBufferMemory
impl Send for ConversationBufferMemory
impl Sync for ConversationBufferMemory
impl Unpin for ConversationBufferMemory
impl UnsafeUnpin for ConversationBufferMemory
impl UnwindSafe for ConversationBufferMemory
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