langchain.memory.summary.ConversationSummaryMemory

class langchain.memory.summary.ConversationSummaryMemory[源代码]

基类:BaseChatMemorySummarizerMixin

会话摘要到聊天记忆。

参数ai_prefix: str = 'AI'
参数buffer: str = ''
参数chat_memory: BaseChatMessageHistory [可选]
参数human_prefix: str = 'Human'
参数input_key: Optional[str] = None
参数llm: BaseLanguageModel [必需]
参数output_key: Optional[str] = None
参数prompt: BasePromptTemplate = PromptTemplate(input_variables=['new_lines', 'summary'], 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? 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:')
参数return_messages: bool = False
参数summary_message_cls: Type[BaseMessage] = <class 'langchain_core.messages.system.SystemMessage'>
async aclear() None

清除内存内容。

返回类型

None

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

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

参数

inputs (Dict[str, Any]) – 向链路的输入。

返回

键值对字典。

返回类型

Dict[str, Any]

async apredict_new_summary(messages: List[BaseMessage], existing_summary: str) str
参数
  • messages (List[BaseMessage]) –

  • existing_summary (str) –

返回类型

字符串

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

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

参数
  • inputs (Dict[str, Any]) –

  • outputs (Dict[str, str]) –

返回类型

None

clear() None[source]

清除内存内容。

返回类型

None

classmethod from_messages(llm: BaseLanguageModel, chat_memory: BaseChatMessageHistory, *, summarize_step: int = 2, **kwargs: Any) ConversationSummaryMemory[source]
参数
返回类型

ConversationSummaryMemory

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

返回历史缓冲区。

参数

inputs (Dict[str, Any]) –

返回类型

Dict[str, Any]

predict_new_summary(messages: List[BaseMessage], existing_summary: str) str
参数
  • messages (List[BaseMessage]) –

  • existing_summary (str) –

返回类型

字符串

save_context(inputs: dict[str, any], outputs: dict[str, str]) None[源代码]

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

参数
  • inputs (Dict[str, Any]) –

  • outputs (Dict[str, str]) –

返回类型

None