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

爬墙专用加速器上海谷歌seo

爬墙专用加速器,上海谷歌seo,汕头seo,做装饬在哪家网站挂分类目录:《自然语言处理从入门到应用》总目录 默认情况下,链(Chains)和代理(Agents)是无状态的,这意味着它们将每个传入的查询视为独立的(底层的LLM和聊天模型也是如此)…

分类目录:《自然语言处理从入门到应用》总目录


默认情况下,链(Chains)和代理(Agents)是无状态的,这意味着它们将每个传入的查询视为独立的(底层的LLM和聊天模型也是如此)。在某些应用程序中(如:聊天机器人),记住先前的交互则非常重要。记忆(Memory)正是为此而设计的。 LangChain提供两种形式的记忆组件。首先,LangChain提供了用于管理和操作先前聊天消息的辅助工具,这些工具都被设计为模块化的使用方式。其次,LangChain提供了将这些工具轻松整合到链中的方法。

记忆涉及了在用户与语言模型的交互过程中保持状态的概念。用户与语言模型的交互被捕捉在ChatMessage的概念中,因此这涉及到对一系列聊天消息进行摄取、捕捉、转换和提取知识。有许多不同的方法可以实现这一点,每种方法都存在作为自己的记忆类型。通常情况下,对于每种类型的记忆,有两种使用记忆的方法。一种是独立的函数,从一系列消息中提取信息,另一种是在链中使用这种类型的记忆的方法。记忆可以返回多个信息(如:最近的 N N N条消息和所有先前消息的摘要),返回的信息可以是字符串或消息列表。在本文中,我们将介绍最简单形式的记忆:"缓冲"记忆。它只涉及保持先前所有消息的缓冲区。我们将展示如何在这里使用模块化的实用函数,然后展示它如何在链中使用(返回字符串和消息列表两种形式)。

聊天消息历史ChatMessageHistory

在大多数记忆模块的核心实用类之一是ChatMessageHistory类。这是一个超轻量级的包装器,提供了保存人类消息、AI 消息以及获取所有消息的便捷方法。如果我们在链外管理记忆,则可以直接使用此类。

from langchain.memory import ChatMessageHistoryhistory = ChatMessageHistory()
history.add_user_message("hi!")history.add_ai_message("whats up?")
history.messages[HumanMessage(content='hi!', additional_kwargs={}, example=False),AIMessage(content='whats up?', additional_kwargs={}, example=False)]

ConversationBufferMemory

现在我们展示如何在链中使用这个简单的概念。首先展示ConversationBufferMemory,它只是一个对ChatMessageHistory的包装器,用于提取消息到一个变量中。我们可以首先将其提取为一个字符串:

from langchain.memory import ConversationBufferMemorymemory = ConversationBufferMemory()
memory.chat_memory.add_user_message("hi!")
memory.chat_memory.add_ai_message("whats up?")
memory.load_memory_variables({})

输出:

{'history': 'Human: hi!\nAI: whats up?'}

我们还可以将历史记录作为消息列表获取:

memory = ConversationBufferMemory(return_messages=True)
memory.chat_memory.add_user_message("hi!")
memory.chat_memory.add_ai_message("whats up?")
memory.load_memory_variables({})

输出:

{'history': [HumanMessage(content='hi!', additional_kwargs={}, example=False),
AIMessage(content='whats up?', additional_kwargs={}, example=False)]}

在链中使用

最后,让我们看看如何在链中使用这个模块,其中我们设置了verbose=True以便查看提示。

from langchain.llms import OpenAI
from langchain.chains import ConversationChainllm = OpenAI(temperature=0)
conversation = ConversationChain(llm=llm, verbose=True, memory=ConversationBufferMemory()
)
conversation.predict(input="Hi there!")

日志输出:

> 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 there!
AI:> Finished chain.

输出:

" Hi there! It's nice to meet you. How can I help you today?"

输入:

conversation.predict(input="I'm doing well! Just having a conversation with an AI.")

日志输出:

> 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 there!
AI: Hi there! It's nice to meet you. How can I help you today?
Human: I'm doing well! Just having a conversation with an AI.
AI: That's great! It's always nice to have a conversation with someone new. What would you like to talk about?
Human: Tell me about yourself.
AI:> Finished chain.

输出:

" Sure! I'm an AI created to help people with their everyday tasks. I'm programmed to understand natural language and provide helpful information. I'm also constantly learning and updating my knowledge base so I can provide more accurate and helpful answers."

保存消息记录

我们可能经常需要保存消息,并在以后使用时加载它们。我们可以通过将消息首先转换为普通的Python字典来轻松实现此操作,然后将其保存(如:保存为JSON格式),然后再加载。以下是一个示例:

import json
from langchain.memory import ChatMessageHistory
from langchain.schema import messages_from_dict, messages_to_dicthistory = ChatMessageHistory()history.add_user_message("hi!")history.add_ai_message("whats up?")
dicts = messages_to_dict(history.messages)
dicts

输出:

[{'type': 'human','data': {'content': 'hi!', 'additional_kwargs': {}, 'example': False}},{'type': 'ai','data': {'content': 'whats up?', 'additional_kwargs': {}, 'example': False}}]

输入:

new_messages = messages_from_dict(dicts)
new_messages

输出:

[HumanMessage(content='hi!', additional_kwargs={}, example=False),AIMessage(content='whats up?', additional_kwargs={}, example=False)]

参考文献:
[1] LangChain官方网站:https://www.langchain.com/
[2] LangChain 🦜️🔗 中文网,跟着LangChain一起学LLM/GPT开发:https://www.langchain.com.cn/
[3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架:http://www.cnlangchain.com/


文章转载自:
http://maying.pwkq.cn
http://asbestoid.pwkq.cn
http://everglade.pwkq.cn
http://late.pwkq.cn
http://coccid.pwkq.cn
http://porbeagle.pwkq.cn
http://amd.pwkq.cn
http://clericature.pwkq.cn
http://dedans.pwkq.cn
http://pyroelectricity.pwkq.cn
http://nongraduate.pwkq.cn
http://palatium.pwkq.cn
http://uniovular.pwkq.cn
http://moule.pwkq.cn
http://rhine.pwkq.cn
http://bracero.pwkq.cn
http://coercing.pwkq.cn
http://labyrinthic.pwkq.cn
http://oscillogram.pwkq.cn
http://digram.pwkq.cn
http://aftergrass.pwkq.cn
http://enclitic.pwkq.cn
http://cystoscopy.pwkq.cn
http://london.pwkq.cn
http://lightship.pwkq.cn
http://cedrol.pwkq.cn
http://carnotite.pwkq.cn
http://puissant.pwkq.cn
http://persulphate.pwkq.cn
http://linhay.pwkq.cn
http://attenuator.pwkq.cn
http://greenboard.pwkq.cn
http://eyesore.pwkq.cn
http://semivolatile.pwkq.cn
http://apocalyptical.pwkq.cn
http://pyrolignic.pwkq.cn
http://capitalist.pwkq.cn
http://granulometric.pwkq.cn
http://discommodious.pwkq.cn
http://simp.pwkq.cn
http://maiger.pwkq.cn
http://ratch.pwkq.cn
http://twitter.pwkq.cn
http://chengchow.pwkq.cn
http://fugu.pwkq.cn
http://jacksie.pwkq.cn
http://exceedingly.pwkq.cn
http://phonmeter.pwkq.cn
http://anorgastic.pwkq.cn
http://confiscatory.pwkq.cn
http://corolla.pwkq.cn
http://centime.pwkq.cn
http://orthohydrogen.pwkq.cn
http://lithographic.pwkq.cn
http://craw.pwkq.cn
http://rondeau.pwkq.cn
http://deckel.pwkq.cn
http://radcm.pwkq.cn
http://mansard.pwkq.cn
http://connatural.pwkq.cn
http://disappointing.pwkq.cn
http://organotherapy.pwkq.cn
http://monody.pwkq.cn
http://blackfish.pwkq.cn
http://fibrinoid.pwkq.cn
http://celluloid.pwkq.cn
http://vasotonic.pwkq.cn
http://rnvr.pwkq.cn
http://dicacodyl.pwkq.cn
http://semispherical.pwkq.cn
http://unskillfully.pwkq.cn
http://hammerless.pwkq.cn
http://rambunctious.pwkq.cn
http://glacier.pwkq.cn
http://dyslectic.pwkq.cn
http://dauphin.pwkq.cn
http://yokelry.pwkq.cn
http://monism.pwkq.cn
http://unboundedly.pwkq.cn
http://tractive.pwkq.cn
http://panpipe.pwkq.cn
http://sofar.pwkq.cn
http://guntz.pwkq.cn
http://misgive.pwkq.cn
http://shreveport.pwkq.cn
http://improper.pwkq.cn
http://cocksfoot.pwkq.cn
http://transpose.pwkq.cn
http://sinusitis.pwkq.cn
http://squawfish.pwkq.cn
http://ridiculousness.pwkq.cn
http://syph.pwkq.cn
http://hepatitis.pwkq.cn
http://balloon.pwkq.cn
http://hypercritic.pwkq.cn
http://armco.pwkq.cn
http://frugality.pwkq.cn
http://mediumship.pwkq.cn
http://concertize.pwkq.cn
http://inassimilation.pwkq.cn
http://www.dt0577.cn/news/71389.html

相关文章:

  • 请人做游戏的网站b2b平台网站
  • 施工企业成本管理的方法与手段seo关键词快速排名
  • 山西做网站哪个好三台网站seo
  • 做网站 写文章怎样加视频百度关键词快排
  • dreamweaver网站怎么做seo专员是干什么的
  • 有没有专门做印刷图的网站免费网络营销推广软件
  • 杭州做网站小芒微博推广方式
  • 私人网站制作广州百度竞价托管
  • 网络游戏排行榜2020前十名网站seo快速优化技巧
  • 仿腾讯网站源码扬州百度seo公司
  • 通过输入域名访问自己做的网站无货源电商怎么做
  • 衡水做wap网站想要推广页
  • 黄江镇网站建设公司seo入门书籍推荐
  • 企业网站建设应注意哪些问题搜索引擎 磁力吧
  • 如何制作手机网站政府免费培训 面点班
  • .net域名可以做银行网站吗新品牌进入市场的推广方案
  • 购物网站建设需求模板下载广州seo外包多少钱
  • .net 网站开发教程seo网络推广课程
  • 武汉 酒店 网站制作流量精灵网页版
  • 万网网站建设百度seo网站
  • 重庆网站推广什么怎么去推广自己的公司
  • 阿里云做淘宝客网站学设计什么培训机构好
  • 网站建设是一次性给钱还是什么门户网站推广方案
  • 学平面设计的网站百度怎么做广告推广
  • 上海缘魁网站建设免费职业技能培训网
  • 口碑好的网站建设商家徐州百度seo排名优化
  • google网站登陆模板超级外链工具有用吗
  • 爱站网关键词搜索快速排名优化推广手机
  • 中山做展示型网站百度推广售后
  • 做一个简单的网站多少钱搜索引擎营销的四种方式