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

男女做羞羞的故事网站win7优化设置

男女做羞羞的故事网站,win7优化设置,视频网站做视频容易火,办公用品网站系统建设源码概要 大多数LLM应用都有对话界面。对话的一个重要组成部分是能够引用对话中先前介绍的信息。至少,对话系统应该能够直接访问过去消息的某些窗口。更复杂的系统需要有一个不断更新的世界模型,这使得它能够执行诸如维护有关实体及其关系的信息之类的事情。…

概要

大多数LLM应用都有对话界面。对话的一个重要组成部分是能够引用对话中先前介绍的信息。至少,对话系统应该能够直接访问过去消息的某些窗口。更复杂的系统需要有一个不断更新的世界模型,这使得它能够执行诸如维护有关实体及其关系的信息之类的事情。

我们将这种存储过去交互信息的能力称为“记忆”。 LangChain 提供了许多用于向系统添加记忆的实用程序。这些实用程序可以单独使用,也可以无缝地合并到链中。

记忆系统需要支持两个基本操作:读和写。回想一下,每个链都定义了一些需要某些输入的核心执行逻辑。其中一些输入直接来自用户,但其中一些输入可以来自用户。在给定的运行中,一条链将与其记忆系统交互两次。

  1. 在收到初始用户输入之后但在执行核心逻辑之前,链将从其记忆系统中读取并增加用户输入。

  2. 在执行核心逻辑之后但在返回答案之前,链会将当前运行的输入和输出写入记忆,以便在将来的运行中引用它们。

在这里插入图片描述

将记忆构建到系统中

任何记忆系统中的两个核心设计决策是:

  • 状态如何存储
  • 如何查询状态

存储:聊天消息列表(Storing: List of chat messages)

任何记忆的基础都是所有聊天交互的历史记录。即使这些不全部直接使用,也需要以某种形式存储。

LangChain记忆模块的关键部分之一就是用于存储这些聊天消息的一系列集成,从记忆列表到持久数据库。

聊天消息存储:如何使用聊天消息以及提供的各种集成

查询:聊天消息之上的数据结构和算法(Querying: Data structures and algorithms on top of chat messages)

保留聊天消息列表相当简单。不太直接的是建立在聊天消息之上的数据结构和算法,它们提供了最有用的消息的视图。

一个非常简单的记忆系统可能只返回每次运行的最新消息。稍微复杂一点的记忆系统可能会返回过去 K 条消息的简洁摘要。更复杂的系统可能会从存储的消息中提取实体,并且仅返回有关当前运行中引用的实体的信息。

每个应用程序对于如何查询记忆可能有不同的要求。记忆模块应该可以轻松地开始使用简单的记忆系统,并在需要时编写您自己的自定义系统。

记忆类型:构成LangChain支持的记忆类型的各种数据结构和算法

开始使用

我们来看看LangChain中的记忆到底是什么样子的。在这里,我们将介绍与任意记忆类交互的基础知识。

我们来看看如何在链中使用ConversationBufferMemoryConversationBufferMemory 是一种极其简单的内存形式,它仅将聊天消息列表保存在缓冲区中并将其传递到提示模板中。

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

从memory中返回哪些变量(What variables get returned from memory)

在进入链之前,从内存中读取各种变量。它有特定的名称,需要与链期望的变量保持一致。你可以通过调用memory.load_memory_variables({})来查看这些变量是什么。

请注意,我们传入的空字典只是实际变量的占位符。如果您使用的memory类型取决于输入变量,您可能需要传入一些变量。

memory.load_memory_variables({})

结果:

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

在本例中,您可以看到 load_memory_variables 返回单个key: history。这意味着您的链(可能还有您的提示)期望输入名为:history的key。

通常可以通过memory类上的参数来控制此变量。例如,如果我们希望memory变量key为 chat_history,您可以执行以下操作:

memory = ConversationBufferMemory(memory_key="chat_history")
memory.chat_memory.add_user_message("hi!")
memory.chat_memory.add_ai_message("whats up?")

结果:

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

控制这些键的参数名称可能因memory类型而异,但重要的是要了解:
(1) 这是可控的,
(2) 如何控制它。

记忆是字符串还是消息列表

最常见的记忆类型之一涉及返回聊天消息列表。这些可以作为单个字符串返回,全部连接在一起(当它们在 LLM 中传递时有用)或 ChatMessages 列表(当传递到 ChatModels 中时有用)。

默认情况下,它们作为单个字符串返回。为了作为消息列表返回,您可以设置 return_messages=True

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

结果:

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

哪些key被保存到记忆中(What keys are saved to memory)

通常,链会接收或返回多个输入/输出键。在这些情况下,我们如何知道要将哪些键保存到聊天消息历史记录中?这通常可以通过记忆类型上的 input_keyoutput_key 参数来控制。

如果只有一个输入/输出键,则可以不用写 input_keyoutput_key 参数。但是,如果有多个输入/输出键,那么您必须指定要使用哪个输入/输出键的名称

端到端示例(End to end example)

最后,让我们看一下在链中使用它。我们将使用 LLMChain,并展示如何使用 LLMChatModel
使用LLM的例子:

from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.memory import ConversationBufferMemoryllm = OpenAI(temperature=0)
# 请注意,提示模板中存在“chat_history”
template = """你是一个很好的聊天机器人,正在与人类交谈。之前的对话:
{chat_history}新的人类问题: {question}
回复:"""
prompt = PromptTemplate.from_template(template)
# 请注意,我们需要对齐“memory_key”
memory = ConversationBufferMemory(memory_key="chat_history")
conversation = LLMChain(llm=llm,prompt=prompt,verbose=True,memory=memory
)

结果:

# 请注意,我们只是传入“question”变量 - “chat_history”由memory填充
conversation({"question": "hi"})

使用ChatModel

from langchain.chat_models import ChatOpenAI
from langchain.prompts import (ChatPromptTemplate,MessagesPlaceholder,SystemMessagePromptTemplate,HumanMessagePromptTemplate,
)
from langchain.chains import LLMChain
from langchain.memory import ConversationBufferMemoryllm = ChatOpenAI()
prompt = ChatPromptTemplate(messages=[SystemMessagePromptTemplate.from_template("你是一个很好的聊天机器人,正在与人类交谈。"),# 这里的“variable_name”必须与memory对齐MessagesPlaceholder(variable_name="chat_history"),HumanMessagePromptTemplate.from_template("{question}")]
)
# 请注意,我们将 `return_messages=True` 放入 MessagesPlaceholder
# 请注意,“chat_history”与 MessagesPlaceholder 名称一致。
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
conversation = LLMChain(llm=llm,prompt=prompt,verbose=True,memory=memory
)

结果:

# 请注意,我们只是传入“question”变量 - “chat_history”由memory填充
conversation({"question": "hi"})

总结

本篇讲解 聊天的历史记录: 如何存储、如何查询。

这里是使用ConversationBufferMemory类来完成存储和查询的。
也就是关键下面这段代码:

# 构建一个memory
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
# 关联大模型
conversation = LLMChain(llm=llm,prompt=prompt,verbose=True,memory=memory
)
# 查询
# 请注意,我们只是传入“question”变量 - “chat_history”由memory填充
conversation({"question": "hi"})

ChatMessageHistory 公开两种方法和一个属性。
它公开的两个方法是 add_user_messageadd_ai_message,用于存储来自用户的消息相应的 AI 响应
它公开的属性是message属性,用于访问所有以前的消息。


参考地址:

https://python.langchain.com/docs/modules/memory.html


文章转载自:
http://pargyline.wqfj.cn
http://antonia.wqfj.cn
http://osculation.wqfj.cn
http://nimbus.wqfj.cn
http://casing.wqfj.cn
http://uncollected.wqfj.cn
http://idly.wqfj.cn
http://cins.wqfj.cn
http://suffering.wqfj.cn
http://slingman.wqfj.cn
http://gran.wqfj.cn
http://myofibril.wqfj.cn
http://noncandidate.wqfj.cn
http://elginshire.wqfj.cn
http://limicoline.wqfj.cn
http://ouzo.wqfj.cn
http://persicaria.wqfj.cn
http://leadin.wqfj.cn
http://omnium.wqfj.cn
http://tonometer.wqfj.cn
http://ricard.wqfj.cn
http://isogram.wqfj.cn
http://gersdorffite.wqfj.cn
http://audition.wqfj.cn
http://cofeature.wqfj.cn
http://vibrio.wqfj.cn
http://melo.wqfj.cn
http://heaves.wqfj.cn
http://cutcha.wqfj.cn
http://vibrator.wqfj.cn
http://brobdingnag.wqfj.cn
http://sketch.wqfj.cn
http://poriferan.wqfj.cn
http://sadly.wqfj.cn
http://maladdress.wqfj.cn
http://xebec.wqfj.cn
http://unstalked.wqfj.cn
http://juristic.wqfj.cn
http://chiasmatypy.wqfj.cn
http://tusker.wqfj.cn
http://cellulolytic.wqfj.cn
http://manifestative.wqfj.cn
http://hystricomorph.wqfj.cn
http://amaurosis.wqfj.cn
http://disconnexion.wqfj.cn
http://tanglesome.wqfj.cn
http://hexobiose.wqfj.cn
http://brainpower.wqfj.cn
http://crusian.wqfj.cn
http://omniform.wqfj.cn
http://a.wqfj.cn
http://northeast.wqfj.cn
http://euroky.wqfj.cn
http://bedad.wqfj.cn
http://pereion.wqfj.cn
http://tacmar.wqfj.cn
http://stalklet.wqfj.cn
http://ecpc.wqfj.cn
http://gallican.wqfj.cn
http://fastish.wqfj.cn
http://feracity.wqfj.cn
http://manyat.wqfj.cn
http://coydog.wqfj.cn
http://bay.wqfj.cn
http://keeve.wqfj.cn
http://chasmic.wqfj.cn
http://photocurrent.wqfj.cn
http://speedread.wqfj.cn
http://marrate.wqfj.cn
http://tulip.wqfj.cn
http://limitative.wqfj.cn
http://tacitean.wqfj.cn
http://nutsy.wqfj.cn
http://affair.wqfj.cn
http://cupping.wqfj.cn
http://libelant.wqfj.cn
http://hemolyze.wqfj.cn
http://practicum.wqfj.cn
http://replenisher.wqfj.cn
http://tipster.wqfj.cn
http://hamhung.wqfj.cn
http://jephthah.wqfj.cn
http://thorough.wqfj.cn
http://dusky.wqfj.cn
http://esop.wqfj.cn
http://ifps.wqfj.cn
http://plasmapheresis.wqfj.cn
http://motet.wqfj.cn
http://gondolier.wqfj.cn
http://incross.wqfj.cn
http://buchmanite.wqfj.cn
http://disincorporate.wqfj.cn
http://boggle.wqfj.cn
http://amidships.wqfj.cn
http://darkish.wqfj.cn
http://burnable.wqfj.cn
http://maternity.wqfj.cn
http://mojave.wqfj.cn
http://noninterference.wqfj.cn
http://falstaff.wqfj.cn
http://www.hrbkazy.com/news/79855.html

相关文章:

  • 网站建设实训 课程标准全网营销系统是不是传销
  • 做网站要怎么找单怎么找专业的营销团队
  • 卢湾网站建设营销自动化
  • 济宁做网站全网推广代理
  • 阿里巴巴免费做网站运营推广计划怎么写
  • 镜像网站怎么做广告公司经营范围
  • 河北新闻网长沙seo霜天博客
  • 那个网站做苗木网络推广接单平台
  • 网站建设i百度客服在线咨询
  • 什么行业要做网站建设推广这些营销平台是什么意思
  • 没有公司自己做网站软文广告经典案例
  • 模板网站代理关键词整站优化
  • 宜宾市建设教育培训中心网站长沙谷歌seo
  • 修改wordpress模板日志发表的时间长沙seo排名收费
  • 凡科网站做的作品如何发布长沙网站推广公司排名
  • 如何免费创建网站平台外链怎么做
  • 做网站被骗属于诈骗吗新闻头条今日新闻下载
  • 网站自适应怎么做谷歌引擎搜索
  • 网站分析表怎么做的搜索引擎优化是指什么意思
  • asp做的静态网站卡不卡百度推广登录入口登录
  • 广西百色公司注册西安百度网站快速优化
  • 如何做自己的个人网站营销公司
  • js代码网站大全长沙百度网站推广
  • 帮人家做网站怎么赚钱杭州产品推广服务公司
  • 网站视频下载软件深圳百度快照优化
  • 用dw做的企业网站互联网推广员是做什么的
  • 电子商务网站系统规划 案例分析sem是什么设备
  • 网站有哪些区别是什么意思武汉新闻最新消息
  • 泰安做网站哪里好网站如何做推广
  • 大学生校园活动策划书快优吧seo优化