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

打电话推销好还是做网站推广好网站制造公司

打电话推销好还是做网站推广好,网站制造公司,宁波网站推广大全,广西远昌建设公司今天要讲以下内容#xff1a; 1.ConversationBufferWindowMemory#xff1a;基于一个固定长度的滑动窗口的“记忆”功能 2.ConversationSummaryMemory#xff1a;总结对话“记忆”功能 3.ConversationSummaryBufferMemory#xff1a;上面两个的结合#xff0c;超过一定…今天要讲以下内容 1.ConversationBufferWindowMemory基于一个固定长度的滑动窗口的“记忆”功能 2.ConversationSummaryMemory总结对话“记忆”功能 3.ConversationSummaryBufferMemory上面两个的结合超过一定token限制之前以对话形式进行存储超过之后进行小结存储。 4.memory.save_context有上下文对话可以通过此插入对话内容可供后续对话内容 5.EntityMemory按命名实体记录对话上下文有重点的存储 1.BufferWindow 我们都知道让AI执行对话需要给它一定的上下文它才能知道我们聊的是什么事情而把我们所有聊天的记录传给openAI肯定是不行的那会耗费有很多的token所以之前我们的操作则都是限制保存上下文今天我们用 Langchain的ConversationBufferWindowMemory来实现记忆上下文对话的过程。 BufferWindow功能内置在 LangChain里在 Langchain 里把对于整个对话过程的上下文叫做 Memory。任何一个 LLMChain我们都可以给它加上一个 Memory来让它记住最近的对话上下文。 #! pip install langchain #! pip install openai from langchain.memory import ConversationBufferWindowMemory from langchain.prompts import PromptTemplate from langchain.chains import LLMChain from langchain.llms import OpenAI import openai, osos.environ[OPENAI_API_KEY] openai.api_key os.environ.get(OPENAI_API_KEY)template 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文 2. 回答限制在100个字以内{chat_history} Human: {human_input} Chatbot:promptPromptTemplate(input_variables[chat_history,human_input],templatetemplate ) # k3保留最近三次对话 memoryConversationBufferWindowMemory(memory_keychat_history,k3) llm_chainLLMChain(llmOpenAI(),promptprompt,memorymemory,verboseTrue ) llm_chain.predict(human_input你是谁?) 结果 Entering new LLMChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文 2. 回答限制在100个字以内Human: 你是谁? Chatbot: Finished chain. 我是一个中国厨师我可以根据你的口味来制作出你喜欢的菜肴。我擅长做中餐并且熟练掌握多种烹饪技巧可以满足不同人的口味需求。 因为我们记忆三次所以我们可以连续对话看看它是否能够记得 llm_chain.predict(human_input烤馕怎么做) 结果 Entering new LLMChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文 2. 回答限制在100个字以内Human: 你是谁? AI: 我是一个中国厨师我可以根据你的口味来制作出你喜欢的菜肴。我擅长做中餐并且熟练掌握多种烹饪技巧可以满足不同人的口味需求。 Human: 烤馕怎么做 Chatbot: Finished chain. 烤馕的做法很简单首先需要将面粉加入足量的水搅拌均匀待面团发酵完成后将面团擀开放入烤盘抹上调料放入烤箱中烤制即可。 继续问 llm_chain.predict(human_input那大盘鸡怎么做) llm_chain.predict(human_input我问你的第一句话是什么) 结果 我的第一句话是“你是谁” 如果此时你在问它我问你的第一句话是什么 它的回答 我的第一句话是“烤馕怎么做” 因为它只会记住三句话我们设置的k做决定。 2.SummaryMemory用小结作为历史记忆 前面的案例是采用多伦对话只记住3次上下文就算是我把次数调整很高token的使用恐怕也是有上限的不能一直记忆可以采用总结之前所说的对话内容就知道大概说的是什么我们用ConversationSummaryMemory。 from langchain.chains import ConversationChain from langchain.memory import ConversationSummaryMemory from langchain.prompts import PromptTemplate from langchain.llms import OpenAI import openai, osllmOpenAI(temperature0) memoryConversationSummaryMemory(llmOpenAI()) prompt_template 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文 2. 回答限制在100个字以内{history} Human: {input} AI:promptPromptTemplate(input_variables[history, input], templateprompt_template ) # 使用ConversationChain可以不用定义prompt来维护历史聊天记录的为了使用中文我们才定义的 conversation_with_summaryConversationChain(llmllm,memorymemory,promptprompt,verboseTrue ) conversation_with_summary.predict(input你好) 结果 Entering new ConversationChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文 2. 回答限制在100个字以内Human: 你好 AI: Finished chain. 你好我可以帮你做菜。我会根据你的口味和喜好结合当地的食材制作出美味可口的菜肴。我会尽力做出最好的菜肴让你满意。 继续问 conversation_with_summary.predict(input烤馕怎么做) 结果 Entering new ConversationChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文 2. 回答限制在100个字以内The human greets the AI and the AI replies by saying it can help the human make food, using local ingredients and tailored to the humans taste and preferences. The AI promises to do its best to make the food satisfactory. Human: 烤馕怎么做 AI: Finished chain. 烤馕是一道简单又美味的中国传统小吃需要用到面粉、糖、油、酵母等材料具体做法是首先将面粉、糖、油、酵母混合搅拌然后揉成面团放入油锅中烤制最后撒上糖粉即可。 此时我们调用memory 的 load_memory_variables 方法可以看到记录下来的 history 是一小段关于对话的英文小结。 memory.load_memory_variables({}) 结果你可以继续问这里的数据会英文内容小结会随着对话变多说明每一次对话都在小结。 {history: \nThe human greets the AI and the AI replies by saying it can help the human make food, using local ingredients and tailored to the humans taste and preferences. The AI promises to do its best to make the food satisfactory. In response to the human asking how to make 烤馕, the AI explains that it is a simple and delicious Chinese traditional snack requiring ingredients such as flour, sugar, oil, and yeast. The specific instructions are to first mix the ingredients together, knead the dough, fry it in an oil pan, and finally sprinkle sugar powder. In response to the human asking how to make 大盘鸡, the AI explains that it is a classic Chinese dish requiring ingredients such as chicken, vegetables, beans, and seasonings. The instructions are to cut the chicken into small pieces, marinate with seasonings; then wash the vegetables and beans and cut them into small pieces. Finally, put the chicken, vegetables, and beans in a pan, add seasonings and cook until done.} 我们在问一个精确的问题 conversation_with_summary.predict(input我上一轮问题是什么) 结果却不精确而是把之前的总结的内容拿了过来因为它记录的也是不精确的内容。 你上一轮问题是如何做烤馕、大盘鸡和烤羊肉串 3.两者结合使用 SummaryBufferMemory ConversationSummaryBufferMemory可以将两者结合我们看怎么使用 # 两者结合使用 SummaryBufferMemory !pip install tiktokenfrom langchain import PromptTemplate from langchain.chains import ConversationChain from langchain.memory import ConversationSummaryBufferMemory from langchain.llms import OpenAISUMMARIZER_TEMPLATE 请将以下内容逐步概括所提供的对话内容并将新的概括添加到之前的概括中形成新的概括。EXAMPLE Current summary: Human询问AI对人工智能的看法。AI认为人工智能是一种积极的力量。New lines of conversation: Human为什么你认为人工智能是一种积极的力量 AI因为人工智能将帮助人类发挥他们的潜能。New summary: Human询问AI对人工智能的看法。AI认为人工智能是一种积极的力量因为它将帮助人类发挥他们的潜能。 END OF EXAMPLECurrent summary: {summary}New lines of conversation: {new_lines}New summary:SUMMARY_PROMPTPromptTemplate(input_variables[summary, new_lines], templateSUMMARIZER_TEMPLATE ) # 当对话的达到max_token_limit长度到多长之后我们就应该调用 LLM 去把文本内容小结一下 memoryConversationSummaryBufferMemory(llmOpenAI(),promptSUMMARY_PROMPT, max_token_limit256)CHEF_TEMPLATE 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文。 2. 对于做菜步骤的回答尽量详细一些。{history} Human: {input} AI:CHEF_PROMPTPromptTemplate(input_variables[history, input], templateCHEF_TEMPLATE ) conversation_with_summarConversationChain(llmOpenAI(model_nametext-davinci-003,stop\n\n,max_tokens2048, temperature0.5),promptCHEF_PROMPT,memorymemory,verboseTrue ) answerconversation_with_summar.predict(input你是谁) print(answer) 结果 Entering new ConversationChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文。 2. 对于做菜步骤的回答尽量详细一些。Human: 你是谁 AI: Finished chain.我是一位中国厨师可以为您提供做菜的帮助。 继续问 answerconversation_with_summar.predict(input葱花饼怎么做) print(answer) 结果 Entering new ConversationChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文。 2. 对于做菜步骤的回答尽量详细一些。Human: 你是谁 AI: 我是一位中国厨师可以为您提供做菜的帮助。 Human: 葱花饼怎么做 AI: Finished chain.葱花饼是一道简单又美味的中国小吃做法如下 1. 将面粉、盐和温水混合搅拌均匀搓成面团 2. 将面团分成小块每块压成薄饼 3. 将葱花切碎撒在饼上 4. 用油烧热锅将饼煎至双面金黄 5. 最后将葱花饼装盘即可。 继续问 answerconversation_with_summar.predict(input那发面饼怎么做呢) 结果可以看到出现了System里面是聊天历史的小结而后面完整记录的实际对话轮数就变少了。 Entering new ConversationChain chain... Prompt after formatting: 你是一个中国厨师用中文回答做菜的问题。你的回答需要满足以下要求: 1. 你的回答必须是中文。 2. 对于做菜步骤的回答尽量详细一些。System: Human询问AI对人工智能的看法。AI认为人工智能是一种积极的力量因为它将帮助人类发挥他们的潜能。Human还询问AI身份AI回答自己是一位中国厨师可以为Human提供做菜的帮助并回答了葱花饼和发面饼怎么做的问题葱花饼需要混合面粉、盐、温水搓成面团压成薄饼 Human: 那发面饼呢 AI: 发面饼需要将面粉、盐、温水、少量油搅拌成面团然后发酵至发起来再搓成小圆球用擀面杖擀成薄饼最后放入油锅中煎至金黄色即可。 Human: 那发面饼怎么做呢 AI:Finished chain. 不同类型的 Memory随着对话轮数的增长占用的 Token 数量的变化。比较合理的方式还是使用这里的 ConversationSummaryBufferMemory这样既可以在记录少数对话内容的时候记住的东西更加精确也可以在对话轮数增长之后既能够记住各种信息又不至于超出 Token 数量的上限。 4.让AI记住重点信息 下面这个例子是如果你之前已经有了一系列的历史对话通过Memory的save_context接口把历史聊天记录灌进去。然后基于这个 Memory 让 AI 接着和用户对话。 from langchain import PromptTemplate from langchain.chains import ConversationChain from langchain.memory import ConversationSummaryBufferMemory from langchain.llms import OpenAISUMMARIZER_TEMPLATE 请将以下内容逐步概括所提供的对话内容并将新的概括添加到之前的概括中形成新的概括。EXAMPLE Current summary: Human询问AI对人工智能的看法。AI认为人工智能是一种积极的力量。New lines of conversation: Human为什么你认为人工智能是一种积极的力量 AI因为人工智能将帮助人类发挥他们的潜能。New summary: Human询问AI对人工智能的看法。AI认为人工智能是一种积极的力量因为它将帮助人类发挥他们的潜能。 END OF EXAMPLECurrent summary: {summary}New lines of conversation: {new_lines}New summary:SUMMARY_PROMPTPromptTemplate(input_variables[summary, new_lines], templateSUMMARIZER_TEMPLATE ) memoryConversationSummaryBufferMemory(llmOpenAI(),promptSUMMARY_PROMPT,max_token_limit40) # 灌入对应的客服历史记录 memory.save_context({input:你好},{output:你好我是客服李四有什么我可以帮助您的么} ) memory.save_context({input:我叫张三在你们这里下了一张订单订单号是 2023ABCD我的邮箱地址是 customerabc.com但是这个订单十几天了还没有收到货},{output:好的您稍等我先为您查询一下您的订单} ) memory.load_memory_variables({}) 结果 {history: System: \nHuman向AI问候AI回答并表示可以为其提供帮助。Human给出自己的订单信息AI表示会先为其查询订单信息。} AI 对整段对话做了小结这里面我们发现重要的订单号和邮箱号都没有记录下来这些又是很重要的只有这些后续才可以根据信息查询和给用户发送信息。 我们通过Langchain的EntityMemory的封装让 AI 自动帮我们提取这样的信息。 from langchain.chains import ConversationChain from langchain.memory import ConversationEntityMemory from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATEentityMemoryConversationEntityMemory(llmllm) conversationConversationChain(llmllm,verboseTrue,promptENTITY_MEMORY_CONVERSATION_TEMPLATE,memoryentityMemory )answerconversation.predict(input我叫张老三在你们这里下了一张订单订单号是 2023ABCD我的邮箱地址是 customerabc.com但是这个订单十几天了还没有收到货) print(answer) 结果 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: {张老三: , 2023ABCD: , customerabc.com: }Current conversation:Last line: Human: 我叫张老三在你们这里下了一张订单订单号是 2023ABCD我的邮箱地址是 customerabc.com但是这个订单十几天了还没有收到货 You: Finished chain. 您好张老三感谢您下订单我们会尽快处理您的订单。我们会尽快为您发货如果您有任何疑问请随时联系我们。 我们把 memory 里面存储的东西打印出来。 print(conversation.memory.entity_store.store) 结果 {张老三: 张老三是一位客户他的订单号是2023ABCD邮箱地址是customerabc.com。, 2023ABCD: 2023ABCD is an order placed by Zhang Lao San with the email address customerabc.com., customerabc.com: customerabc.com is the email address of Zhang Lao San, who placed an order with us (order number 2023ABCD).}EntityMemory 里面不仅存储了这些命名实体的名字也对应的把命名实体所关联的上下文记录了下来。我们此时来问相关问题他就能回答出来 answerconversation.predict(input我刚才的订单号是多少) print(answer) 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:{2023ABCD: 2023ABCD is an order placed by Zhang Lao San with the email address customerabc.com.}Current conversation:Human: 我叫张老三在你们这里下了一张订单订单号是 2023ABCD我的邮箱地址是 customerabc.com但是这个订单十几天了还没有收到货AI: 您好张老三感谢您下订单我们会尽快处理您的订单。我们会尽快为您发货如果您有任何疑问请随时联系我们。Last line:Human: 我刚才的订单号是多少You: Finished chain.您的订单号是2023ABCD。 再问一个 answerconversation.predict(input订单2023ABCD是谁的订单) print(answer) 结果 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:{2023ABCD: 2023ABCD is an order placed by Zhang Lao San with the email address customerabc.com, and is the order number provided by the customer.}Current conversation:Human: 我叫张老三在你们这里下了一张订单订单号是 2023ABCD我的邮箱地址是 customerabc.com但是这个订单十几天了还没有收到货AI: 您好张老三感谢您下订单我们会尽快处理您的订单。我们会尽快为您发货如果您有任何疑问请随时联系我们。Human: 我刚才的订单号是多少AI: 您的订单号是2023ABCD。Last line:Human: 订单2023ABCD是谁的订单You: Finished chain.订单2023ABCD是张老三的订单他的邮箱地址是customerabc.com。
http://www.w-s-a.com/news/809259/

相关文章:

  • dw制作一个环保网站模板下载吉安网站建设收费
  • 深圳珠宝网站设计北京高端网站建设优势
  • 合肥企业制作网站wordpress创建网站
  • 织梦网站开发兼职wordpress 中间截取缩略图
  • 南通制作网站旅游搭建网站
  • 专业做商铺的网站个人网页html模板完整代码
  • 什么网站做美食最好最专业关键词推广是什么意思
  • 自助建设网站软件网站导航网站可以做吗
  • 网站模板放哪长沙网站优化分析
  • 泉州网站建设价钱网站模板素材
  • 南通网站托管js建设网站外网
  • 成都企业网站公司wordpress内页模板
  • 58同城建网站怎么做wordpress评论显示数字ip
  • 免费制作论坛网站模板免费下载北京网站制作长沙
  • 旅游网网站建设网站如何自己做seo
  • 如何验证网站所有权做二手家具回收哪个网站好
  • 做哪种网站赚钱项目开发流程
  • 网站建设和网站网络推广网站建设软件定制
  • 站长工具网址查询全球云邮登陆网站
  • 宁波 住房和建设局网站网上发帖推广
  • 平面设计在线网站工业设计公司有哪些
  • 福州网站设计外包公司网站做的比较好
  • 如何设计网站首页网站开发综合技能实训心得体会
  • 用织梦做的网站好用吗w网站链接如何做脚注
  • 东莞做网站公司在哪哪里有网站培训的
  • 做宣传 为什么要做网站那重庆网站建设公司在线联系
  • 网站设计制作售价多少钱制作图片的软件是
  • 网站验证码目录简单带数据库的网站模版
  • 制作网站用c#做前台网站建设专题的意义
  • 广西建设职业技术学院教育网站牡丹区建设局网站