当前位置: 首页 > news >正文

工程建设造价全过程监督网站二级建造师考试科目

工程建设造价全过程监督网站,二级建造师考试科目,河北建设执业信息网官网,梭子手做鱼网站Langchain 的 Conversation summary memory 现在让我们看一下使用稍微复杂的内存类型 - ConversationSummaryMemory 。这种类型的记忆会随着时间的推移创建对话的摘要。这对于随着时间的推移压缩对话中的信息非常有用。对话摘要内存对发生的对话进行总结,并将当前摘…

Langchain 的 Conversation summary memory

现在让我们看一下使用稍微复杂的内存类型 - ConversationSummaryMemory 。这种类型的记忆会随着时间的推移创建对话的摘要。这对于随着时间的推移压缩对话中的信息非常有用。对话摘要内存对发生的对话进行总结,并将当前摘要存储在内存中。然后可以使用该内存将迄今为止的对话摘要注入提示/链中。此内存对于较长的对话最有用,因为在提示中逐字保留过去的消息历史记录会占用太多令牌。

我们首先来探讨一下这种存储器的基本功能。

示例代码,

from langchain.memory import ConversationSummaryMemory, ChatMessageHistory
from langchain.llms import OpenAI
memory = ConversationSummaryMemory(llm=OpenAI(temperature=0))
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(llm=OpenAI(temperature=0), return_messages=True)
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(llm=OpenAI(temperature=0), chat_memory=history, return_messages=True)
memory.buffer

输出结果,

    '\nThe human greets the AI, to which the AI responds with a friendly greeting.'

Using in a chain

让我们看一下在链中使用它的示例,再次设置 verbose=True 以便我们可以看到提示。

示例代码,

from langchain.llms import OpenAI
from langchain.chains import ConversationChain
llm = OpenAI(temperature=0)
conversation_with_summary = ConversationChain(llm=llm, memory=ConversationSummaryMemory(llm=OpenAI()),verbose=True
)
conversation_with_summary.predict(input="Hi, what's up?")

输出结果,

    > Entering new ConversationChain chain...Prompt after formatting:The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:Human: Hi, what's up?AI:> Finished chain." Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?"

示例代码,

conversation_with_summary.predict(input="Tell me more about it!")

输出结果,

    > Entering new ConversationChain chain...Prompt after formatting:The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:The human greeted the AI and asked how it was doing. The AI replied that it was doing great and was currently helping a customer with a technical issue.Human: Tell me more about it!AI:> Finished chain." Sure! The customer is having trouble with their computer not connecting to the internet. I'm helping them troubleshoot the issue and figure out what the problem is. So far, we've tried resetting the router and checking the network settings, but the issue still persists. We're currently looking into other possible solutions."

示例代码,

conversation_with_summary.predict(input="Very cool -- what is the scope of the project?")

输出结果,

    > Entering new ConversationChain chain...Prompt after formatting:The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.Current conversation:The human greeted the AI and asked how it was doing. The AI replied that it was doing great and was currently helping a customer with a technical issue where their computer was not connecting to the internet. The AI was troubleshooting the issue and had already tried resetting the router and checking the network settings, but the issue still persisted and they were looking into other possible solutions.Human: Very cool -- what is the scope of the project?AI:> Finished chain." The scope of the project is to troubleshoot the customer's computer issue and find a solution that will allow them to connect to the internet. We are currently exploring different possibilities and have already tried resetting the router and checking the network settings, but the issue still persists."

完结!

http://www.yayakq.cn/news/476752/

相关文章:

  • 公路建设项目可行性研究报告编制办法哪个网站查最新版泰安考试信息网官网
  • 秦皇岛网站制作报价网站建设申请报告
  • 河北衡水市网站制作的公司室内设计网站参考
  • 网站建设公司咋样桂林市区有什么好玩的地方景点
  • 英迈思做的网站怎么样国外著名网站建设公司
  • 河北建设厅录入业绩的网站wordpress主题插件下载失败
  • 济源市住房和城乡建设局网站做ppt的网站有哪些
  • 自己建一个网站需要多少钱?做网站需要哪些技术支持
  • html5 企业 网站广东东莞市
  • 网站建设方案样本asp.net网站设计分工
  • 招商网站建设简介网上推广平台
  • 网站跳转到另外一个网站怎么做莱州一中网站
  • 女与男做那个的视频网站网站空间是不是服务器
  • 用手机怎么做网站顺企网下载安装
  • 公司网站必须做可信认证吗沧州建设银行招聘网站
  • 谷歌收录网站福州 哈尔滨网站建设 网络服务
  • 手机作网站服务器网站用什么颜色
  • 做蛋糕视频教学网站网站搭建心得体会
  • 网站开发合同存在的缺陷网站建设成果
  • 如何创建网站下载登录页面设计模板
  • 网站开发能自学吗wordpress简单论坛
  • 南山的网站建设公司wordpress页面模板链接
  • 西宁网站设计我的网站在百度搜不到
  • 免费做网站怎么做网站吗vs做网站添加背景
  • 做seo 教你如何选择网站关键词查看网站开发
  • 视频网站自己做服务器学生服务器租用
  • 潮汕美食网站怎么做陕西做天然气公司网站
  • 品牌管理公司网站建设网站建设注册小程序
  • 青浦集团网站建设wordpress分类目录插件
  • 广西建设厅网站是什么做照片书网站好