pub struct ConversationBufferMemory { /* private fields */ }Expand description
Conversation Buffer Memory
将所有对话历史保存在内存中。
§示例
ⓘ
use langchainrust::ConversationBufferMemory;
let mut memory = ConversationBufferMemory::new();
// 保存对话
let inputs = HashMap::from([("input".to_string(), "你好".to_string())]);
let outputs = HashMap::from([("output".to_string(), "你好!".to_string())]);
memory.save_context(&inputs, &outputs).await?;
// 加载记忆
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
设置输入键名
Sourcepub fn with_output_key(self, key: String) -> Self
pub fn with_output_key(self, key: String) -> Self
设置输出键名
Sourcepub fn with_memory_key(self, key: String) -> Self
pub fn with_memory_key(self, key: String) -> Self
设置记忆变量名
Sourcepub fn with_return_messages(self, return_messages: bool) -> Self
pub fn with_return_messages(self, return_messages: bool) -> Self
设置是否返回消息对象
Sourcepub fn from_chat_memory(chat_memory: ChatMessageHistory) -> Self
pub fn from_chat_memory(chat_memory: ChatMessageHistory) -> Self
从已有历史创建
Sourcepub fn chat_memory(&self) -> &ChatMessageHistory
pub fn chat_memory(&self) -> &ChatMessageHistory
获取聊天历史
Sourcepub fn chat_memory_mut(&mut self) -> &mut ChatMessageHistory
pub fn chat_memory_mut(&mut self) -> &mut ChatMessageHistory
获取可变的聊天历史
Trait Implementations§
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,
加载记忆变量 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,
保存上下文 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