哪个php网站外包软文发布平台最值得信赖?
摘要:php网站外包,软文发布平台哪家好,以绿色为主的网站,京东网站网站建设是什么Langchain 的 Conversation summary memory 现在让我们看一下使用稍微复杂的内存类型 - ConversationSummaryM
php网站外包,软文发布平台哪家好,以绿色为主的网站,京东网站网站建设是什么Langchain 的 Conversation summary memory 现在让我们看一下使用稍微复杂的内存类型 - ConversationSummaryMemory 。这种类型的记忆会随着时间的推移创建对话的摘要。这对于随着时间的推移压缩对话中的信息非常有用。对话摘要内存对发生的对话进行总结#xff0c;并将当前摘… Langchain 的 Conversation summary memory 现在让我们看一下使用稍微复杂的内存类型 - ConversationSummaryMemory 。这种类型的记忆会随着时间的推移创建对话的摘要。这对于随着时间的推移压缩对话中的信息非常有用。对话摘要内存对发生的对话进行总结并将当前摘要存储在内存中。然后可以使用该内存将迄今为止的对话摘要注入提示/链中。此内存对于较长的对话最有用因为在提示中逐字保留过去的消息历史记录会占用太多令牌。
我们首先来探讨一下这种存储器的基本功能。
示例代码
from langchain.memory import ConversationSummaryMemory, ChatMessageHistory
from langchain.llms import OpenAImemory ConversationSummaryMemory(llmOpenAI(temperature0))
memory.save_context({input: hi}, {output: whats up})memory.load_memory_variables({})输出结果 {history: \nThe human greets the AI, to which the AI responds.}我们还可以获取历史记录作为消息列表如果您将其与聊天模型一起使用这非常有用。
memory ConversationSummaryMemory(llmOpenAI(temperature0), return_messagesTrue)
memory.save_context({input: hi}, {output: whats up})memory.load_memory_variables({})输出结果 {history: [SystemMessage(content\nThe human greets the AI, to which the AI responds., additional_kwargs{})]}我们也可以直接使用 predict_new_summary 方法。
messages memory.chat_memory.messages
previous_summary
memory.predict_new_summary(messages, previous_summary)输出结果 \nThe human greets the AI, to which the AI responds.Initializing with messages
如果您有此类之外的消息您可以使用 ChatMessageHistory 轻松初始化该类。加载期间将计算摘要。
示例代码
history ChatMessageHistory()
history.add_user_message(hi)
history.add_ai_message(hi there!)memory ConversationSummaryMemory.from_messages(llmOpenAI(temperature0), chat_memoryhistory, return_messagesTrue)memory.buffer输出结果 \nThe human greets the AI, to which the AI responds with a friendly greeting.Using in a chain
让我们看一下在链中使用它的示例再次设置 verboseTrue 以便我们可以看到提示。
