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

中国核工业第二二建设有限公司是国企吗天津seo选天津旗舰科技a

中国核工业第二二建设有限公司是国企吗,天津seo选天津旗舰科技a,火狐 网站开发,北京网站制作培训班分类目录#xff1a;《自然语言处理从入门到应用》总目录 默认情况下#xff0c;链#xff08;Chains#xff09;和代理#xff08;Agents#xff09;是无状态的#xff0c;这意味着它们将每个传入的查询视为独立的#xff08;底层的LLM和聊天模型也是如此#xff09;…分类目录《自然语言处理从入门到应用》总目录 默认情况下链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(contenthi!, additional_kwargs{}, exampleFalse),AIMessage(contentwhats up?, additional_kwargs{}, exampleFalse)]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_messagesTrue) memory.chat_memory.add_user_message(hi!) memory.chat_memory.add_ai_message(whats up?) memory.load_memory_variables({})输出 {history: [HumanMessage(contenthi!, additional_kwargs{}, exampleFalse), AIMessage(contentwhats up?, additional_kwargs{}, exampleFalse)]}在链中使用 最后让我们看看如何在链中使用这个模块其中我们设置了verboseTrue以便查看提示。 from langchain.llms import OpenAI from langchain.chains import ConversationChainllm OpenAI(temperature0) conversation ConversationChain(llmllm, verboseTrue, memoryConversationBufferMemory() ) conversation.predict(inputHi 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! Its nice to meet you. How can I help you today?输入 conversation.predict(inputIm 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! Its nice to meet you. How can I help you today? Human: Im doing well! Just having a conversation with an AI. AI: Thats great! Its 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! Im an AI created to help people with their everyday tasks. Im programmed to understand natural language and provide helpful information. Im 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(contenthi!, additional_kwargs{}, exampleFalse),AIMessage(contentwhats up?, additional_kwargs{}, exampleFalse)]参考文献 [1] LangChain官方网站https://www.langchain.com/ [2] LangChain ️ 中文网跟着LangChain一起学LLM/GPT开发https://www.langchain.com.cn/ [3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架http://www.cnlangchain.com/
http://www.hkea.cn/news/14472126/

相关文章:

  • 芜湖手机网站开发国外产品短视频拍摄
  • 餐饮网站欣赏徐州关键词优化如何
  • 国内wordpress最好的主题seo优化对网店的推广的作用为
  • 可以做课程的网站wordpress商城中文
  • 高新苏州网站建设wordpress私活
  • 营销型企业网站优点自媒体平台源码
  • 推荐国外网站设计做网站首页应该考虑什么
  • 专业手机建站价格wordpress全景插件
  • 百度云盘网站开发动漫制作专业大学
  • 工商企业网站河北省永清县建设局网站
  • 惠州网站关键词排名最牛网站建设
  • 四川省城乡住房和城乡建设厅网站首页竞价在什么网站上做
  • 天津高端网站建设制作成都酒店设计十大公司排名
  • 网站怎么下载视频广告平面设计教程
  • 杭州做公司网站哪家好龙华网站建设 信科网络
  • 网站建设的功能要求wordpress+下载媒体库
  • 临沂网站制作公司6wordpress扁平化风格主题
  • 快速搭建网站工具王也踏青
  • 学校网站设计的目的搜索引擎网址
  • 工业设计灵感网站华为云免费云服务器
  • 手机网站知识网站推荐几个免费的
  • 网站建设公司汉狮网络中国建设银行手机银行
  • 建网站要多少钱 东莞咸阳网站建设学校
  • 用什么网站做一手楼好上海设计公司排名招聘
  • 推广营销海外网站东莞网站建设营销哪家好
  • wordpress手机适配seo新人培训班
  • 做自媒体素材搬运网站wordpress 文章分页 插件
  • 建网站中企动力最行自己怎么健网站视频教程
  • 网站抓取QQ获取系统济南做外贸的网站公司吗
  • 安徽企业平台网站建设网站开发拓扑图