langchain.memory.summary_buffer
.ConversationSummaryBufferMemory¶
- class langchain.memory.summary_buffer.ConversationSummaryBufferMemory[source]¶
父类:
BaseChatMemory
,SummarizerMixin
用于存储对话记忆的具有摘要功能的缓冲区。
- 参数 ai_prefix: str = 'AI'¶
- 参数 chat_memory: BaseChatMessageHistory [可选]¶
- 参数 human_prefix: str = 'Human'¶
- 参数 input_key: Optional[str] = None¶
- 参数 llm: BaseLanguageModel [必需]¶
- 参数 max_token_limit: int = 2000¶
- 参数 memory_key: str = 'history'¶
- 参数moving_summary_buffer:str =''¶
- 参数output_key:Optional[str] =None¶
- 参数prompt:BasePromptTemplate =PromptTemplate(input_variables=['new_lines', 'summary'], template='逐步总结所提供的对话行,并将总结添加到之前的总结中,返回新的总结。\n\nEXAMPLE\n当前总结:\nThe human asks what the AI thinks of artificial intelligence. The AI thinks artificial intelligence is a force for good.\n\n新对话行:\nHuman: Why do you think artificial intelligence is a force for good?\nAI: Because artificial intelligence will help humans reach their full potential.\n\n新总结:\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\n当前总结:\n{summary}\n\n新对话行:\n{new_lines}\n\n新总结:')¶
- 参数return_messages:bool =False¶
- param summary_message_cls: Type[BaseMessage] = <class 'langchain_core.messages.system.SystemMessage'>¶
- async abuffer() Union[str, List[BaseMessage]] [source]¶
异步内存缓冲区。
- 返回类型
Union[str, List[BaseMessage]]
- async aload_memory_variables(inputs: Dict[str, Any]) Dict[str, Any] [source]¶
异步返回给定文本输入的键值对。
- 参数
inputs (Dict[str, Any]) –
- 返回类型
Dict[str, Any]
- async apredict_new_summary(messages: List[BaseMessage], existing_summary: str) str ¶
- 参数
messages (List[BaseMessage]) –
existing_summary (str) –
- 返回类型
str
- async asave_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None [source]¶
异步地将本次对话的上下文保存到缓冲区。
- 参数
inputs (Dict[str, Any]) –
outputs (Dict[str, str]) –
- 返回类型
None
- load_memory_variables(inputs: Dict[str, Any]) Dict[str, Any] [源代码]¶
返回历史缓冲区。
- 参数
inputs (Dict[str, Any]) –
- 返回类型
Dict[str, Any]
- predict_new_summary(messages: List[BaseMessage], existing_summary: str) str ¶
- 参数
messages (List[BaseMessage]) –
existing_summary (str) –
- 返回类型
str
- save_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None [源代码]¶
将此对话的上下文保存到缓冲区。
- 参数
inputs (Dict[str, Any]) –
outputs (Dict[str, str]) –
- 返回类型
None
- 属性buffer:Union[str, List[BaseMessage]]¶
内存的字符串缓冲区。