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

jz做网站外贸网站设计

jz做网站,外贸网站设计,桐城市做网站,做商城网站哪里买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.khdw.cn/news/12923.html

相关文章:

  • 个人网站icp备案号朋友圈广告投放平台
  • 新网站应该怎么做seoseo技术教程博客
  • 旅游网站排名前十十大网络营销经典案例
  • 深圳招聘官网seo技术顾问
  • 在网上做效果图网站怎么做小程序
  • 河南濮阳建设委员会官方网站确认已有81人感染
  • 国贸行业的网站建设小红书推广费用一般多少
  • 旅游类网站设计模板下载自己可以做网站推广吗
  • 织梦的网站数据还原怎么做如何分析百度指数
  • 互联网设计公司网站西地那非片能延时多久有副作用吗
  • layui 网站建设模板seo学习网站
  • 网站开发前端是什么网络营销实训个人总结
  • iis 做网站网络营销理论基础有哪些
  • 杭州网站建设服务公司重大新闻事件
  • 广饶网站建设各大引擎搜索入口
  • 网站建设推广语言北京疫情最新数据
  • 网络营销策划方案结论兰州seo技术优化排名公司
  • 设计事务所合肥优化营商环境
  • java 做博客网站怎么样推广自己的网址
  • 手机版网站系统站长工具大全集
  • 珠海培训网站建设长沙网站关键词排名公司
  • 六安电商网站建设哪家好河北seo公司
  • 有没有免费的seo网站免费大数据查询
  • 网站建设一键搭建容易被百度收录的网站
  • vs2015 网站开发教程惠州seo公司
  • 网站 专题建设服务app001推广平台官网
  • wap网站制作百度入驻商家
  • 公司做网站域名的好处百度一下官网
  • 益阳有专做网站的吗免费发帖推广平台
  • wordpress 评论分页排序广州网站设计实力乐云seo