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

平度市建设局网站深圳最近一个星期新闻

平度市建设局网站,深圳最近一个星期新闻,建外贸营销型网站,付费推广外包Langchain 的 Conversation buffer window memory ConversationBufferWindowMemory 保存一段时间内对话交互的列表。它仅使用最后 K 个交互。这对于保持最近交互的滑动窗口非常有用,因此缓冲区不会变得太大。 我们首先来探讨一下这种存储器的基本功能。 示例代码&…

Langchain 的 Conversation buffer window memory

ConversationBufferWindowMemory 保存一段时间内对话交互的列表。它仅使用最后 K 个交互。这对于保持最近交互的滑动窗口非常有用,因此缓冲区不会变得太大。

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

示例代码,

from langchain.memory import ConversationBufferWindowMemory
memory = ConversationBufferWindowMemory( k=1)
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.save_context({"input": "not much you"}, {"output": "not much"})
memory.load_memory_variables({})

输出结果,

    {'history': 'Human: not much you\nAI: not much'}

我们还可以获取历史记录作为消息列表(如果您将其与聊天模型一起使用,这非常有用)。

示例代码,

memory = ConversationBufferWindowMemory( k=1, return_messages=True)
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.save_context({"input": "not much you"}, {"output": "not much"})
memory.load_memory_variables({})

输出结果,

    {'history': [HumanMessage(content='not much you', additional_kwargs={}),AIMessage(content='not much', additional_kwargs={})]}

Using in a chain

让我们看一下示例,再次设置 verbose=True 以便我们可以看到提示。

from langchain.llms import OpenAI
from langchain.chains import ConversationChain
conversation_with_summary = ConversationChain(llm=OpenAI(temperature=0), # We set a low k=2, to only keep the last 2 interactions in memorymemory=ConversationBufferWindowMemory(k=2), 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="What's their issues?")

输出结果,

    > 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:  Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?Human: What's their issues?AI:> Finished chain." The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected."

示例代码,

conversation_with_summary.predict(input="Is it going well?")

输出结果,

    > 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:  Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?Human: What's their issues?AI:  The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected.Human: Is it going well?AI:> Finished chain." Yes, it's going well so far. We've already identified the problem and are now working on a solution."

示例代码,

# Notice here that the first interaction does not appear.
conversation_with_summary.predict(input="What's the solution?")

输出结果,

    > 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: What's their issues?AI:  The customer is having trouble connecting to their Wi-Fi network. I'm helping them troubleshoot the issue and get them connected.Human: Is it going well?AI:  Yes, it's going well so far. We've already identified the problem and are now working on a solution.Human: What's the solution?AI:> Finished chain." The solution is to reset the router and reconfigure the settings. We're currently in the process of doing that."

完结!

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

相关文章:

  • 微网站怎么注册天河区网站建设
  • iis网站服务器安全隐患wordpress html结尾
  • 豫icp郑州网站建设企业为什么要开发网址
  • 网页网站制作公司网站限时抢购怎么做
  • 网站活动打造深圳建设监理协会网站
  • 潍坊市做网站的公司企业网站制作免费下载
  • 局域网网站开发企业网站源码 php
  • 厦门免费网站建设图形化html编辑器
  • 产品网站设计论文做外贸网站要多少钱
  • wordpress制作的网站模板wordpress更新服务评论
  • 电影网站模板源代码临沂网站建设电话
  • 个人网站整站下载建设规划许可证公示网站
  • 全国大型网站建设传奇网站怎么建设
  • 陕西网站制有赞分销员的功能和规则
  • 网站建设模拟软件wordpress前端是什么
  • 北京网站建设联系电话成免费crm破解版
  • 免费企业建站系统源码商城通网站建设
  • 深圳住房和城乡建设局网站大气ppt模板
  • 建站公司跑路了域名怎么办免费ppt模板下载爱ppt
  • 太仓专业网站建设网站建设中需要注意的问题
  • 天津企悦在线网站建设个人网站建设方法和过程
  • 做网站为什么不要源代码网站域名收费吗
  • 徐州市城乡建设局门户网站中国建筑集团领导名单
  • 怎么样在百度搜到自己的网站菏泽网站建设电话
  • 濮阳网站建设厦门网站建设外包公司
  • 济南街道办网站建设网站设计过程怎么写
  • 怎么做网站竞价推广陕西省建设八大员官方网站
  • 什么网站做的很好长沙功能网站建设
  • 什么值得买网站模板营销培训机构哪家最专业
  • 网站开发主管要做什么网站维护外包