Skip to main content

ConversationBufferMemory

Struct ConversationBufferMemory 

Source
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

Source

pub fn new() -> Self

创建新的对话缓冲区记忆

Source

pub fn with_input_key(self, key: String) -> Self

设置输入键名

Source

pub fn with_output_key(self, key: String) -> Self

设置输出键名

Source

pub fn with_memory_key(self, key: String) -> Self

设置记忆变量名

Source

pub fn with_return_messages(self, return_messages: bool) -> Self

设置是否返回消息对象

Source

pub fn from_chat_memory(chat_memory: ChatMessageHistory) -> Self

从已有历史创建

Source

pub fn chat_memory(&self) -> &ChatMessageHistory

获取聊天历史

Source

pub fn chat_memory_mut(&mut self) -> &mut ChatMessageHistory

获取可变的聊天历史

Trait Implementations§

Source§

impl BaseMemory for ConversationBufferMemory

Source§

fn memory_variables(&self) -> Vec<&str>

获取记忆变量名 Read more
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,

加载记忆变量 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,

保存上下文 Read more
Source§

fn clear<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

清空记忆
Source§

impl Debug for ConversationBufferMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConversationBufferMemory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more