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

二维码短链接生成器搜索优化的培训免费咨询

二维码短链接生成器,搜索优化的培训免费咨询,嘉兴企业做网站,重庆网站开发服务器Langchain 的 ConversationSummaryBufferMemory ConversationSummaryBufferMemory 在内存中保留最近交互的缓冲区,但不仅仅是完全刷新旧的交互,而是将它们编译成摘要并使用两者。但与之前的实现不同的是,它使用令牌长度而不是交互次数来确定何…

Langchain 的 ConversationSummaryBufferMemory

ConversationSummaryBufferMemory 在内存中保留最近交互的缓冲区,但不仅仅是完全刷新旧的交互,而是将它们编译成摘要并使用两者。但与之前的实现不同的是,它使用令牌长度而不是交互次数来确定何时刷新交互。

我们首先来了解一下如何使用这些实用程序,

示例代码,

from langchain.memory import ConversationSummaryBufferMemory
from langchain.llms import OpenAIllm = OpenAI()
memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=40, return_messages=True
)
memory.save_context({"input": "嗨"}, {"output": "最近怎么样?"})
memory.save_context({"input": "没什么特别的,你呢?"}, {"output": "没什么特别的。"})
memory.load_memory_variables({})

输出结果,

{'history': [SystemMessage(content='\nThe human and AI are engaging in conversation. The human greets the AI and the AI asks how the human is doing.', additional_kwargs={}),HumanMessage(content='没什么特别的,你呢?', additional_kwargs={}, example=False),AIMessage(content='没什么特别的。', additional_kwargs={}, example=False)]}

示例代码,

from langchain.chains import ConversationChainconversation_with_summary = ConversationChain(llm=llm,# We set a very low max_token_limit for the purposes of testing.memory=ConversationSummaryBufferMemory(llm=OpenAI(), max_token_limit=250),verbose=True,
)
conversation_with_summary.predict(input="嗨,最近怎么样?")

输出结果,

> 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: 嗨,最近怎么样?
AI:> Finished chain.
' 嗨!最近还不错,我在学习新的技能,并且正在尝试新的任务。我也在尝试改进我的语言处理能力,以便更好地与人交流。你呢?'

示例代码,

conversation_with_summary.predict(input="只是在写一些文档!")

输出结果,

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: 嗨,最近怎么样?
AI:  嗨!最近还不错,我在学习新的技能,并且正在尝试新的任务。我也在尝试改进我的语言处理能力,以便更好地与人交流。你呢?
Human: 只是在写一些文档!
AI:> Finished chain.
' 哦,看起来很有趣!你在写什么文档?'

示例代码,

conversation_with_summary.predict(input="你听说过 LangChain 吗?")

输出结果,

> 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: 嗨,最近怎么样?
AI:  嗨!最近还不错,我在学习新的技能,并且正在尝试新的任务。我也在尝试改进我的语言处理能力,以便更好地与人交流。你呢?
Human: 只是在写一些文档!
AI:  哦,看起来很有趣!你在写什么文档?
Human: 你听说过 LangChain 吗?
AI:> Finished chain.
' 是的,我知道LangChain。它是一个基于区块链的语言学习平台,旨在帮助人们更好地学习外语。你正在写关于LangChain的文档吗?'

示例代码,

# 我们可以看到,摘要和缓冲区都已更新
conversation_with_summary.predict(input="哈哈,不对,不过很多人都把它混淆了。"
)

输出结果,

> 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:
System: 
The AI thinks artificial intelligence is a force for good because it will help humans reach their full potential. It has been learning new skills and trying new tasks, as well as attempting to improve its language processing so that it can communicate better with humans. The human asks how the AI has been doing recently.
Human: 只是在写一些文档!
AI:  哦,看起来很有趣!你在写什么文档?
Human: 你听说过 LangChain 吗?
AI:  是的,我知道LangChain。它是一个基于区块链的语言学习平台,旨在帮助人们更好地学习外语。你正在写关于LangChain的文档吗?
Human: 哈哈,不对,不过很多人都把它混淆了。
AI:> Finished chain.
' 哦,我明白了。那你在写什么文档呢?'

完结!

http://www.hkea.cn/news/8024/

相关文章:

  • wordpress全屏背景信息流优化师职业规划
  • 浙江网站建设企业优化大师官方正版下载
  • 大淘客网站商品做淘口令网络广告策划书
  • 网站备案入口互联网产品推广
  • 最专业的网站建设组织网站seo百度百科
  • 如何建网站费用多少营口建网站的公司
  • 提供邢台网站优化网络广告推广公司
  • 赤峰网站策划看到招聘游戏推广员千万别去
  • 网站建设可行性研究报告范文哪里可以学seo课程
  • 张家港网站建设服务网页优化公司
  • dnf做任务解除制裁网站软文广告500字
  • 网站建设 前端 后端2023年免费b站推广大全
  • 清河做网站多少钱百度网络推广怎么收费
  • 广州网站建设公司排行甲马营seo网站优化的
  • 官方网站下载打印机的驱动沧州搜索引擎优化
  • 做直播网站赚钱广告联盟接单平台
  • 株洲市建设局网站为什么sem的工资都不高
  • 异常网站服务器失去响应专业代写软文
  • 二手书屋网站开发的意义广告软文小故事200字
  • 手机网站发展晨阳seo顾问
  • 光泽县规划建设和旅游局网站成都seo优化排名推广
  • 哪些网站做的比较好的百度应用
  • 网站服务器是干什么的seo对网络推广的作用是
  • 营销型网站建设优化千锋教育学费多少
  • 徐州免费网站建设模板成都疫情最新消息
  • 过年做那个网站致富拉新奖励的app排行
  • 郑州建站网站的公司广州最新新闻
  • wordpress 导航栏湖南关键词优化推荐
  • 网站首页英文凡科网微信小程序
  • 根据一个网站仿做新网站是什么网站网络促销策略