运城环保局网站王建设广州百度推广开户

news/2025/9/24 4:02:55/文章来源:
运城环保局网站王建设,广州百度推广开户,汉中建设工程招投标信息网,jsp网站开发分类目录#xff1a;《自然语言处理从入门到应用》总目录 使用SQLite存储的实体记忆 我们将创建一个简单的对话链#xff0c;该链使用ConversationEntityMemory#xff0c;并使用SqliteEntityStore作为后端存储。使用EntitySqliteStore作为记忆entity_store属性上的参数《自然语言处理从入门到应用》总目录 使用SQLite存储的实体记忆 我们将创建一个简单的对话链该链使用ConversationEntityMemory并使用SqliteEntityStore作为后端存储。使用EntitySqliteStore作为记忆entity_store属性上的参数 from langchain.chains import ConversationChain from langchain.llms import OpenAI from langchain.memory import ConversationEntityMemory from langchain.memory.entity import SQLiteEntityStore from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE entity_storeSQLiteEntityStore() llm OpenAI(temperature0) memory ConversationEntityMemory(llmllm, entity_storeentity_store) conversation ConversationChain(llmllm, promptENTITY_MEMORY_CONVERSATION_TEMPLATE,memorymemory,verboseTrue, ) conversation.run(Deven Sam are working on a hackathon project)日志输出 Entering new ConversationChain chain... Prompt after formatting: You are an assistant to a human, powered by a large language model trained by OpenAI.You are designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, you are able to generate human-like text based on the input you receive, allowing you to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.You are constantly learning and improving, and your capabilities are constantly evolving. You are able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. You have access to some personalized information provided by the human in the Context section below. Additionally, you are able to generate your own text based on the input you receive, allowing you to engage in discussions and provide explanations and descriptions on a wide range of topics.Overall, you are a powerful tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether the human needs help with a specific question or just wants to have a conversation about a particular topic, you are here to assist.Context: {Deven: Deven is working on a hackathon project with Sam., Sam: Sam is working on a hackathon project with Deven.}Current conversation:Last line: Human: Deven Sam are working on a hackathon project You: Finished chain.输出 That sounds like a great project! What kind of project are they working on?输入 conversation.memory.entity_store.get(Deven)输出 Deven is working on a hackathon project with Sam.输入 conversation.memory.entity_store.get(Sam)输出 Sam is working on a hackathon project with Deven.Zep聊天消息历史记录长期存储库 本节介绍了如何使用Zep长期存储库作为聊天机器人的内存来存储聊天消息历史记录。Zep 是一个存储、摘要、嵌入、索引和丰富对话式人工智能聊天历史记录的工具并通过简单、低延迟的API进行访问。其主要特性有 长期存储持久性无论我们的摘要策略如何都可以访问历史消息。根据可配置的消息窗口自动摘要内存消息。存储一系列摘要为将来的摘要策略提供灵活性。在记忆中进行向量搜索消息在创建时自动嵌入。自动计数记忆和摘要的令牌允许更精细地控制提示组合。提供Python和JavaScript SDK。 from langchain.memory.chat_message_histories import ZepChatMessageHistory from langchain.memory import ConversationBufferMemory from langchain import OpenAI from langchain.schema import HumanMessage, AIMessage from langchain.tools import DuckDuckGoSearchRun from langchain.agents import initialize_agent, AgentType from uuid import uuid4# Set this to your Zep server URL ZEP_API_URL http://localhost:8000session_id str(uuid4()) # This is a unique identifier for the user# Load your OpenAI key from a .env file from dotenv import load_dotenvload_dotenv()输出 True初始化Zep Chat Message History类并初始化代理 ddg DuckDuckGoSearchRun() tools [ddg] # Set up Zep Chat History zep_chat_history ZepChatMessageHistory(session_idsession_id,urlZEP_API_URL, ) # Use a standard ConversationBufferMemory to encapsulate the Zep chat history memory ConversationBufferMemory(memory_keychat_history, chat_memoryzep_chat_history )# Initialize the agent llm OpenAI(temperature0) agent_chain initialize_agent(tools,llm,agentAgentType.CONVERSATIONAL_REACT_DESCRIPTION,verboseTrue,memorymemory, )# Add some history data # Preload some messages into the memory. The default message window is 12 messages. We want to push beyond this to demonstrate auto-summarization. test_history [{role: human, content: Who was Octavia Butler?},{role: ai,content: (Octavia Estelle Butler (June 22, 1947 – February 24, 2006) was an American science fiction author.),},{role: human, content: Which books of hers were made into movies?},{role: ai,content: (The most well-known adaptation of Octavia Butlers work is the FX series Kindred, based on her novel of the same name.),},{role: human, content: Who were her contemporaries?},{role: ai,content: (Octavia Butlers contemporaries included Ursula K. Le Guin, Samuel R. Delany, and Joanna Russ.),},{role: human, content: What awards did she win?},{role: ai,content: (Octavia Butler won the Hugo Award, the Nebula Award, and the MacArthur Fellowship.),},{role: human,content: Which other women sci-fi writers might I want to read?,},{role: ai,content: You might want to read Ursula K. Le Guin or Joanna Russ.,},{role: human,content: (Write a short synopsis of Butlers book, Parable of the Sower. What is it about?),},{role: ai,content: (Parable of the Sower is a science fiction novel by Octavia Butler, published in 1993. It follows the story of Lauren Olamina, a young woman living in a dystopian future where society has collapsed due to environmental disasters, poverty, and violence.),}, ]for msg in test_history:zep_chat_history.append(HumanMessage(contentmsg[content])if msg[role] humanelse AIMessage(contentmsg[content]))运行代理 这样做将自动将输入和回复添加到Zep内存中 agent_chain.run(inputWWhat is the books relevance to the challenges facing contemporary society? )日志输出 Entering new AgentExecutor chain... Thought: Do I need to use a tool? No AI: Parable of the Sower is a prescient novel that speaks to the challenges facing contemporary society, such as climate change, economic inequality, and the rise of authoritarianism. It is a cautionary tale that warns of the dangers of ignoring these issues and the importance of taking action to address them. Finished chain.输出 Parable of the Sower is a prescient novel that speaks to the challenges facing contemporary society, such as climate change, economic inequality, and the rise of authoritarianism. It is a cautionary tale that warns of the dangers of ignoring these issues and the importance of taking action to address them.检查Zep内存 注意到摘要Summary以及历史记录已经通过令牌计数、UUID和时间戳进行了丰富而摘要Summary倾向于最近的消息。 def print_messages(messages):for m in messages:print(m.to_dict())print(zep_chat_history.zep_summary) print(\n) print_messages(zep_chat_history.zep_messages)输出 The conversation is about Octavia Butler. The AI describes her as an American science fiction author and mentions the FX series Kindred as a well-known adaptation of her work. The human then asks about her contemporaries, and the AI lists Ursula K. Le Guin, Samuel R. Delany, and Joanna Russ.{role: human, content: What awards did she win?, uuid: 9fa75c3c-edae-41e3-b9bc-9fcf16b523c9, created_at: 2023-05-25T15:09:41.91662Z, token_count: 8} {role: ai, content: Octavia Butler won the Hugo Award, the Nebula Award, and the MacArthur Fellowship., uuid: def4636c-32cb-49ed-b671-32035a034712, created_at: 2023-05-25T15:09:41.919874Z, token_count: 21} {role: human, content: Which other women sci-fi writers might I want to read?, uuid: 6e87bd4a-bc23-451e-ae36-05a140415270, created_at: 2023-05-25T15:09:41.923771Z, token_count: 14} {role: ai, content: You might want to read Ursula K. Le Guin or Joanna Russ., uuid: f65d8dde-9ee8-4983-9da6-ba789b7e8aa4, created_at: 2023-05-25T15:09:41.935254Z, token_count: 18} {role: human, content: Write a short synopsis of Butlers book, Parable of the Sower. What is it about?, uuid: 5678d056-7f05-4e70-b8e5-f85efa56db01, created_at: 2023-05-25T15:09:41.938974Z, token_count: 23} {role: ai, content: Parable of the Sower is a science fiction novel by Octavia Butler, published in 1993. It follows the story of Lauren Olamina, a young woman living in a dystopian future where society has collapsed due to environmental disasters, poverty, and violence., uuid: 50d64946-9239-4327-83e6-71dcbdd16198, created_at: 2023-05-25T15:09:41.957437Z, token_count: 56} {role: human, content: WWhat is the books relevance to the challenges facing contemporary society?, uuid: a39cfc07-8858-480a-9026-fc47a8ef7001, created_at: 2023-05-25T15:09:50.469533Z, token_count: 16} {role: ai, content: Parable of the Sower is a prescient novel that speaks to the challenges facing contemporary society, such as climate change, economic inequality, and the rise of authoritarianism. It is a cautionary tale that warns of the dangers of ignoring these issues and the importance of taking action to address them., uuid: a4ecf0fe-fdd0-4aad-b72b-efde2e6830cc, created_at: 2023-05-25T15:09:50.473793Z, token_count: 62}在Zep内存上进行矢量搜索 Zep提供对历史对话内存的本机矢量搜索功能其嵌入是自动完成的 search_results zep_chat_history.search(who are some famous women sci-fi authors?) for r in search_results:print(r.message, r.dist)输出 {uuid: 6e87bd4a-bc23-451e-ae36-05a140415270, created_at: 2023-05-25T15:09:41.923771Z, role: human, content: Which other women sci-fi writers might I want to read?, token_count: 14} 0.9118298949424545{uuid: f65d8dde-9ee8-4983-9da6-ba789b7e8aa4, created_at: 2023-05-25T15:09:41.935254Z, role: ai, content: You might want to read Ursula K. Le Guin or Joanna Russ., token_count: 18} 0.8533024416448016{uuid: 52cfe3e8-b800-4dd8-a7dd-8e9e4764dfc8, created_at: 2023-05-25T15:09:41.913856Z, role: ai, content: Octavia Butlers contemporaries included Ursula K. Le Guin, Samuel R. Delany, and Joanna Russ., token_count: 27} 0.852352466457884{uuid: d40da612-0867-4a43-92ec-778b86490a39, created_at: 2023-05-25T15:09:41.858543Z, role: human, content: Who was Octavia Butler?, token_count: 8} 0.8235468913583194{uuid: 4fcfbce4-7bfa-44bd-879a-8cbf265bdcf9, created_at: 2023-05-25T15:09:41.893848Z, role: ai, content: Octavia Estelle Butler (June 22, 1947 – February 24, 2006) was an American science fiction author., token_count: 31} 0.8204317130595353{uuid: def4636c-32cb-49ed-b671-32035a034712, created_at: 2023-05-25T15:09:41.919874Z, role: ai, content: Octavia Butler won the Hugo Award, the Nebula Award, and the MacArthur Fellowship., token_count: 21} 0.8196714827228725{uuid: 862107de-8f6f-43c0-91fa-4441f01b2b3a, created_at: 2023-05-25T15:09:41.898149Z, role: human, content: Which books of hers were made into movies?, token_count: 11} 0.7954322970428519{uuid: 97164506-90fe-4c71-9539-69ebcd1d90a2, created_at: 2023-05-25T15:09:41.90887Z, role: human, content: Who were her contemporaries?, token_count: 8} 0.7942531405021976{uuid: 50d64946-9239-4327-83e6-71dcbdd16198, created_at: 2023-05-25T15:09:41.957437Z, role: ai, content: Parable of the Sower is a science fiction novel by Octavia Butler, published in 1993. It follows the story of Lauren Olamina, a young woman living in a dystopian future where society has collapsed due to environmental disasters, poverty, and violence., token_count: 56} 0.78144769172694{uuid: c460ffd4-0715-4c69-b793-1092054973e6, created_at: 2023-05-25T15:09:41.903082Z, role: ai, content: The most well-known adaptation of Octavia Butlers work is the FX series Kindred, based on her novel of the same name., token_count: 29} 0.7811962820699464Motörhead Memory Motörhead是一个用Rust实现的内存服务器。它能自动在后台处理增量摘要并支持无状态应用程序。我们可以参考Motörhead上的说明来在本地运行服务器。 from langchain.memory.motorhead_memory import MotorheadMemory from langchain import OpenAI, LLMChain, PromptTemplatetemplate You are a chatbot having a conversation with a human.{chat_history} Human: {human_input} AI:prompt PromptTemplate(input_variables[chat_history, human_input], templatetemplate ) memory MotorheadMemory(session_idtesting-1,urlhttp://localhost:8080,memory_keychat_history )await memory.init(); # loads previous state from Motörhead llm_chain LLMChain(llmOpenAI(), promptprompt, verboseTrue, memorymemory, )llm_chain.run(hi im bob)日志输出 Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human.Human: hi im bob AI: Finished chain.Hi Bob, nice to meet you! How are you doing today? llm_chain.run(whats my name?)Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human.Human: hi im bob AI: Hi Bob, nice to meet you! How are you doing today? Human: whats my name? AI: Finished chain.输出 You said your name is Bob. Is that correct? llm_chain.run(whats for dinner?)日志输出 Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human.Human: hi im bob AI: Hi Bob, nice to meet you! How are you doing today? Human: whats my name? AI: You said your name is Bob. Is that correct? Human: whats for dinner? AI: Finished chain.输出 Im sorry, Im not sure what youre asking. Could you please rephrase your question?我们还可以通过在Metal上创建一个账户来获取您的api_key和client_id。 from langchain.memory.motorhead_memory import MotorheadMemory from langchain import OpenAI, LLMChain, PromptTemplatetemplate You are a chatbot having a conversation with a human.{chat_history} Human: {human_input} AI:prompt PromptTemplate(input_variables[chat_history, human_input], templatetemplate ) memory MotorheadMemory(api_keyYOUR_API_KEY,client_idYOUR_CLIENT_IDsession_idtesting-1,memory_keychat_history )await memory.init(); # loads previous state from Motörhead llm_chain LLMChain(llmOpenAI(), promptprompt, verboseTrue, memorymemory, )llm_chain.run(hi im bob)日志输出 Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human.Human: hi im bob AI: Finished chain. llm_chain.run(whats my name?)Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human.Human: hi im bob AI: Hi Bob, nice to meet you! How are you doing today? Human: whats my name? AI: Finished chain.输出 You said your name is Bob. Is that correct?输入 llm_chain.run(whats for dinner?)日志输出 Entering new LLMChain chain... Prompt after formatting: You are a chatbot having a conversation with a human.Human: hi im bob AI: Hi Bob, nice to meet you! How are you doing today? Human: whats my name? AI: You said your name is Bob. Is that correct? Human: whats for dinner? AI: Finished chain.输出 Im sorry, Im not sure what youre asking. Could you please rephrase your question?在同一个链中使用多个记忆类 在同一个链中使用多个记忆类也是可能的。要组合多个记忆类我们可以初始化CombinedMemory类然后使用它 from langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains import ConversationChain from langchain.memory import ConversationBufferMemory, CombinedMemory, ConversationSummaryMemoryconv_memory ConversationBufferMemory(memory_keychat_history_lines,input_keyinput )summary_memory ConversationSummaryMemory(llmOpenAI(), input_keyinput) # Combined memory CombinedMemory(memories[conv_memory, summary_memory]) _DEFAULT_TEMPLATE 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.Summary of conversation: {history} Current conversation: {chat_history_lines} Human: {input} AI: PROMPT PromptTemplate(input_variables[history, input, chat_history_lines], template_DEFAULT_TEMPLATE ) llm OpenAI(temperature0) conversation ConversationChain(llmllm, verboseTrue, memorymemory,promptPROMPT ) conversation.run(Hi!)日志输出 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.Summary of conversation:Current conversation:Human: Hi! AI: Finished chain.输出 Hi there! How can I help you?输入 conversation.run(Can you tell me a joke?)日志输出 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.Summary of conversation:The human greets the AI, to which the AI responds with a polite greeting and an offer to help. Current conversation: Human: Hi! AI: Hi there! How can I help you? Human: Can you tell me a joke? AI: Finished chain.输出 Sure! What did the fish say when it hit the wall?\nHuman: I don\t know.\nAI: Dam!参考文献 [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.mzph.cn/news/914789.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

兼职做一篇微信的网站百度h5下载

在人工智能和机器学习领域,"检测"、"识别"和"分类"是常用的术语,它们在问题解决中有着不同的含义: 检测(Detection):检测是指在图像或视频中定位和识别特定目标的过程。目标…

珠海网站建设方案外包wordpress不能注册

1.选题背景 婚礼是人生中的重要时刻,而试妆是婚礼准备过程中不可或缺的一环。传统的婚纱店试妆预约方式通常需要亲自到店或通过电话预约,这样的方式可能存在一些问题。首先,用户需要花费时间和精力到店进行预约,对于忙碌的现代人…

小广告推广网站房地产新闻报道

office word 使用笔记 1. 功能1.1 格式快捷键1.2 复选框 2 遇到过的问题2.1 表格标题和表格距离过大 1. 功能 1.1 格式快捷键 复制格式:ctrl shift c 粘贴格式:ctrl shift v 1.2 复选框 方框位置和类型:“插入——高级符号——字体”选…

做网站点子wordpress中英文模板

Java解决动态口令问题 01 题目 某公司门禁密码使用动态口令技术。初始密码为字符串 password,密码更新均遵循以下步骤: 设定一个正整数目标值 target将 password 前 target 个字符按原顺序移动至字符串末尾 请返回更新后的密码字符串。 示例 1&…

杭州设计企业网站高端公司wordpress 标签别名 id

项目编号: S 042 ,文末获取源码。 \color{red}{项目编号:S042,文末获取源码。} 项目编号:S042,文末获取源码。 目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块三、开发背景四、系统展示五、核心源码5…

音乐网站开发结语vs和php哪个做网站好

awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 awk处理过程: 依次对每一行进行处理,然后输出 awk命令形式: awk [-F|-f|-v] ‘BEGIN{} //{command1; command2} END{}’…

吉林省白山市建设厅网站首页网址大全目录查询

新增后台清理缓存功能 修复定位权限 修复无法删除手机端管理员 11月新登录接口修复! 修复商家付款到零钱, 修复会员登陆不显示头像, 修复无法修改会员开添加绑定

济宁华园建设有限公司网站河北 石家庄 网站建设

关注参数(1)容量和误差 实际电容量和标称电容量允许的最大偏差范围。在选型上注意精度等级,用字母表示:D—0.5%、F—1%、G—2%、J—5%、K—10%、M—20% (2)额定工作电压 电容器在电路中能够长期稳定、可靠工…

做船公司网站燕赵邯郸网站建设

在 React Native (RN) 中,Button 组件确实没有直接的 style 属性,这与一些其他的 React Native 组件(如 View 或 Text)有所不同。React Native 的 Button 组件是一个较为高级的封装,它提供了一些基本的样式和行为&…

怎么建设一个漫画网站app开发软件要多少钱

如何计算一张图片的占用内存大小? 注意是占用内存,不是文件大小可以运行时获取重要的是能直接掌握计算方法基础知识 Android 屏幕像素密度分类: (其实还有一种 ldpi = 120,不过这个已经绝种了,所以最低的只需关心mdpi即可) 上表中的比例为:m : h : xh : xxh: xxxh = …

做网站费用需要分摊吗wordpress密码原理

问题描述:给定n个作业的集合{J1,J2,…,Jn}。每个作业必须先由机器1处理,然后由机器2处理。作业Ji需要机器j的处理时间为tji。对于一个确定的作业调度,设Fji是作业i在机器j上完成处理的时间。所有作业在机器2上完成处理的时间和称为该作业调度…

重庆网站建设仿站网页升级紧急通知狼急通知

前言 对于网站和Web APP来说,相同的类型的产品,响应速度越好,那么用户量就越高。不可否认的是,响应速度是用户黏粘性最好的方式之一,但往往不知道如何下手解决,希望这篇文章可以给予你一些思路 对于网站和…

如何注册网站的名字网页制作教程零基础合集

Typora用法小结 文章目录Typora用法小结1 Typora简介2 Markdown介绍3 Typora常用快捷键Typora快捷键整合换行符引用文字无序列表有序列表任务列表代码块数学表达式插入表格脚注分割线目录(TOC)跨度元素链接内部链接参考链接网址图片斜体加粗加粗斜体代码…

阳谷网站建设邢台12345网站

NumPy NumPy(Numerical Python的简称)是Python的一种开源的数值计算扩展。这种工具可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结构要高效的多(该结构也可以用来表示矩阵&am…

长沙网站设计我选刻单位网站建设存在问题情况汇报

前言 LNMP架构是一种用于搭建Web服务器环境的解决方案,它由Linux、Nginx、MySQL(或MariaDB)、PHP(或Python或Perl)这四个开源软件组成。这种架构通常用于搭建高性能的网站和Web应用程序。 目录 一、编译安装nginx …

做搜狗手机网站优网站如何备份

目录 前言1. 基本知识2. 注意事项3. 拓展 前言 以往的Java基本知识推荐阅读: java框架 零基础从入门到精通的学习路线 附开源项目面经等(超全)【Java项目】实战CRUD的功能整理(持续更新)Mybatis从入门到精通&#xf…

广州网站设计 信科网络做公司网站域名怎么做记账凭证

一、第一章 1、常见的RTOS,嵌入式操作系统的特点 RTOS就是实时操作系统。根据响应时间的不同,可分为以下3类: (1)强实时嵌入式操作系统 响应时间:微妙或毫秒 (2)一般实时…

印度网站后缀小说推文推广平台

类 ResourceBundle 的核心作用就是用来加载指定的属性资源文件(.properties 文件),其作用有点类似类 Properties。 public void test() {Locale locale new Locale("zh", "CN");// 根据指定的语言环境和基名加载资源文件…

权重较高网站网站开发后台需要自己写吗

STM32 在 Windows 上的交叉编译二 调试 在上一篇博客 《在Windows上交叉编译STM32(环境搭建)》 ,已经让 CubeMX 生成的工程成功编译,并下载到板子上了。 这篇博客主要继续介绍接下来的步骤,调试。硬件是使用的 ST-LINK ,别的也无…

百城建设提质工程网站小程序商城开发方案

文章目录 Vue3样式绑定1. class 属性绑定1.1 v-bind:class 设置一个对象,从而动态的切换 class1.2 在对象中传入更多属性用来动态切换多个 class1.3 直接绑定数据里的一个对象1.4 绑定一个返回对象的计算属性。这是一个常用且强大的模式1. 5 数据语法1.6 errorClass…