对话摘要缓冲记忆#

class langchain.memory.summary_buffer.ConversationSummaryBufferMemory[source]#

基础类:BaseChatMemory, SummarizerMixin

自版本0.3.1起已弃用:请参阅迁移指南:https://python.langchain.com/docs/versions/migrating_memory/ 在langchain==1.0.0之前不会移除。

带有总结器的缓冲区,用于存储对话记忆。

提供对话的运行摘要以及对话中的最新消息,条件是对话中的总令牌数不超过某个限制。

param ai_prefix: str = 'AI'#
param chat_memory: BaseChatMessageHistory [Optional]#
param human_prefix: str = 'Human'#
param input_key: str | None = None#
param llm: BaseLanguageModel [Required]#
param max_token_limit: int = 2000#
param memory_key: str = 'history'#
param moving_summary_buffer: str = ''#
param output_key: str | None = None#
param prompt: BasePromptTemplate = PromptTemplate(input_variables=['new_lines', 'summary'], input_types={}, partial_variables={}, template='Progressively summarize the lines of conversation provided, adding onto the previous summary returning a new summary.\n\nEXAMPLE\nCurrent summary:\nThe human asks what the AI thinks of artificial intelligence. The AI thinks artificial intelligence is a force for good.\n\nNew lines of conversation:\nHuman: Why do you think artificial intelligence is a force for good?\nAI: Because artificial intelligence will help humans reach their full potential.\n\nNew summary:\nThe human asks what the AI thinks of artificial intelligence. The AI thinks artificial intelligence is a force for good because it will help humans reach their full potential.\nEND OF EXAMPLE\n\nCurrent summary:\n{summary}\n\nNew lines of conversation:\n{new_lines}\n\nNew summary:')#
param return_messages: bool = False#
param summary_message_cls: Type[BaseMessage] = <class 'langchain_core.messages.system.SystemMessage'>#
async abuffer() str | List[BaseMessage][source]#

异步内存缓冲区。

Return type:

str | 列表[BaseMessage]

async aclear() None[source]#

异步清除内存内容。

Return type:

async aload_memory_variables(inputs: Dict[str, Any]) Dict[str, Any][source]#

异步返回给定链的文本输入的键值对。

Parameters:

输入 (字典[字符串, 任意类型])

Return type:

Dict[str, Any]

async apredict_new_summary(messages: List[BaseMessage], existing_summary: str) str#
Parameters:
Return type:

字符串

async aprune() None[source]#

如果缓冲区超过最大令牌限制,则异步修剪缓冲区

Return type:

async asave_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None[source]#

异步保存此对话的上下文到缓冲区。

Parameters:
  • inputs (Dict[str, Any])

  • outputs (Dict[str, str])

Return type:

clear() None[source]#

清除内存内容。

Return type:

load_memory_variables(inputs: Dict[str, Any]) Dict[str, Any][source]#

返回历史缓冲区。

Parameters:

输入 (字典[字符串, 任意类型])

Return type:

Dict[str, Any]

predict_new_summary(messages: List[BaseMessage], existing_summary: str) str#
Parameters:
Return type:

字符串

prune() None[source]#

如果缓冲区超过最大令牌限制,则进行修剪

Return type:

save_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None[source]#

将此对话的上下文保存到缓冲区。

Parameters:
  • inputs (Dict[str, Any])

  • outputs (Dict[str, str])

Return type:

classmethod validate_prompt_input_variables(values: Dict) Dict[source]#

验证提示输入变量是否一致。

Parameters:

(字典)

Return type:

字典

property buffer: str | List[BaseMessage]#

内存的字符串缓冲区。