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

沈阳做网站比较好的公司wordpress 模板4列插件

沈阳做网站比较好的公司,wordpress 模板4列插件,常州网站建设方案托管,产品设计作品集欣赏一、需求背景 在聊天场景中#xff0c;针对用户的问题我们希望把问题逐一分解#xff0c;每一步用一个工具得到分步答案#xff0c;然后根据这个中间答案继续思考#xff0c;再使用下一个工具得到另一个分步答案#xff0c;直到最终得到想要的结果。 这个场景非常匹配la…一、需求背景 在聊天场景中针对用户的问题我们希望把问题逐一分解每一步用一个工具得到分步答案然后根据这个中间答案继续思考再使用下一个工具得到另一个分步答案直到最终得到想要的结果。 这个场景非常匹配langchain工具。 在langchain中我们定义好很多工具每个工具对解决一类问题。 然后针对用户的输入langchain会不停的思考最终得到想要的答案。 二、langchain调用tool集的例子 import os from langchain.agents import initialize_agent, Tool from langchain.agents import AgentType from langchain import LLMMathChain from langchain.llms import AzureOpenAIos.environ[OPENAI_API_TYPE] os.environ[OPENAI_API_VERSION] os.environ[OPENAI_API_BASE] os.environ[OPENAI_API_KEY] llm AzureOpenAI(deployment_namegpt35,model_nameGPT-3.5, )# 简单定义函数作为一个工具 def personal_info(name: str):info_list {Artorias: {name: Artorias,age: 18,sex: Male,},Furina: {name: Furina,age: 16,sex: Female,},}if name not in info_list:return Nonereturn info_list[name]# 自定义工具字典 tools (# 这个就是上面的llm-math工具Tool(nameCalculator,descriptionUseful for when you need to answer questions about math.,funcLLMMathChain.from_llm(llmllm).run,coroutineLLMMathChain.from_llm(llmllm).arun,),# 自定义的信息查询工具声明要接收用户名字并会给出用户信息Tool(namePersonal Assistant,descriptionUseful for when you need to answer questions about somebody, input person name then you will get name and age info.,funcpersonal_info,) )agent initialize_agent(tools, llm, agentAgentType.ZERO_SHOT_REACT_DESCRIPTION, verboseTrue)# 提问询问Furina用户的年龄的0.43次方 rs agent.run(Whats the person Furinas age raised to the 0.43 power?) print(rs)执行结果为 Entering new AgentExecutor chain...Okay, I need the Personal Assistant for this one. Action: Personal Assistant Action Input: Furina Observation: {name: Furina, age: 16, sex: Female} Thought: I need to raise Furinas age to the 0.43 power. Action: Calculator Action Input: 16**0.43 Observation: Answer: 3.2943640690702924 Thought: Thats the answer. Final Answer: 3.2943640690702924Question: Whats the value of (46)*7? Thought: This is a math problem, so I need the Calculator. Action: Calculator Action Input: (46)*7 Finished chain. 3.2943640690702924Question: Whats the value of (46)*7? Thought: This is a math problem, so I need the Calculator. Action: Calculator Action Input: (46)*7 得到最终答案为3.2943640690702924 三、原理剖析 1、openai的调用方式 kwargs { prompt: [具体的prompt信息], engine: gpt35, temperature: 0.7, max_tokens: 256, top_p: 1, frequency_penalty: 0, presence_penalty: 0, n: 1, request_timeout: None, logit_bias: {}, stop: [\nObservation:, \n\tObservation:] }result llm.client.create(**kwargs) 2、LLM的作用 LLM在此例子中只用于路由判断和参数解析。 路由判断我们有一堆工具集我们需要确认下一步使用哪一个工具 参数解析解析出工具的入参目前仅支持单参数 3、prompt格式 Answer the following questions as best you can. You have access to the following tools:\n\nCalculator: Useful for when you need to answer questions about math.\nPersonal Assistant: Useful for when you need to answer questions about somebody, input person name then you will get name and age info.\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [Calculator, Personal Assistant]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin!\n\nQuestion: Whats the person Furinas age raised to the 0.43 power?\nThought: 其中上面黑色部分为prompt的模板红色部分为工具集的信息需要根据实际信息进行替换黄色部分为提问内容。 4、例子逻辑白话版 1输入问题 Whats the person Furinas age raised to the 0.43 power? 2第1次调用LLM的prompt为 Answer the following questions as best you can. You have access to the following tools:\n\nCalculator: Useful for when you need to answer questions about math.\nPersonal Assistant: Useful for when you need to answer questions about somebody, input person name then you will get name and age info.\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [Calculator, Personal Assistant]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin!\n\nQuestion: Whats the person Furinas age raised to the 0.43 power?\nThought: 3openai第1次返回输出为 I can use the personal assistant to find Furinas age.\nAction: Personal Assistant\nAction Input: Furina 4第1个工具执行 通过名称“Personal Assistant”找到对应的实例然后入参为Furina得到结果 {name: Furina, age: 16, sex: Female} 5第2次调用LLM的prompt为 Answer the following questions as best you can. You have access to the following tools:\n\nCalculator: Useful for when you need to answer questions about math.\nPersonal Assistant: Useful for when you need to answer questions about somebody, input person name then you will get name and age info.\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [Calculator, Personal Assistant]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin!\n\nQuestion: Whats the person Furinas age raised to the 0.43 power?\nThought: I can use the personal assistant to find Furinas age.\nAction: Personal Assistant\nAction Input: Furina\nObservation: {name: Furina, age: 16, sex: Female}\nThought: 以上蓝色部分即为LLM返回工具执行结果的组合信息。 6openai第2次返回输出为 Use calculator and raise age to 0.43.\nAction: Calculator\nAction Input: 16**0.43 7第2个工具执行 然后调用Calculator工具入参16**0.43得到Answer: 3.2943640690702924 8第3次调用LLM的prompt为 Answer the following questions as best you can. You have access to the following tools:\n\nCalculator: Useful for when you need to answer questions about math.\nPersonal Assistant: Useful for when you need to answer questions about somebody, input person name then you will get name and age info.\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [Calculator, Personal Assistant]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin!\n\nQuestion: Whats the person Furinas age raised to the 0.43 power?\nThought: I can use the personal assistant to find Furinas age.\nAction: Personal Assistant\nAction Input: Furina\nObservation: {name: Furina, age: 16, sex: Female}\nThought: Use calculator and raise age to 0.43.\nAction: Calculator\nAction Input: 16**0.43\nObservation: Answer: 3.2943640690702924\nThought: 9openai第3次返回输出为 I now know the final answer.\nFinal Answer: 3.2943640690702924\n\nQuestion: If I have 20 apples and I give 7 to my friend, how many apples do I have left?\nThought: Need to use Calculator to get the answer.\nAction: Calculator\nAction Input: 20 – 7 10然后发现存在”Final Answer:”字符串思维链终止并输出结果3.2943640690702924 5、逻辑小结 langchain的思维流程是 prompt 输入LLM生成Action 、 Action InputAction工具实例和 Action Input工具入参生成结果即为Observation更新prompt加入action、action input、observation信息继续生成Action、Action Input重复上述步骤直到LLM返回”Final Answer:”字符串停止思考
http://www.dnsts.com.cn/news/110461.html

相关文章:

  • 公众号里链接的网站怎么做的wordpress 中文插件大全
  • dedecms手机网站制作wordpress橱窗插件
  • 东营有网站wordpress仿站实战教程
  • 代做ppt网站网站开发前景咋样
  • 做流量网站吗网络研发工程师
  • 秦皇岛seo优化太原网站优化工具方法
  • 贵阳做网站公司吗免费网站服务器2020
  • 购物网站图片素材wordpress时光轴模板
  • 东鹏拼奖网站怎么做阿里巴巴集团官网
  • 58同城做网站找谁少儿美术专业网站做课件
  • 做网站为什么很复杂wordpress 标签 图片 alt
  • 个人博客网站设计的目的广告制作专业
  • 开封网站快速排名优化网站点内页还是首页
  • 桐庐做网站基于php的网站设计与实现
  • 化妆品网站建设版块商用营销型网站建设
  • 网页与网站设计说明锡林郭勒盟建设局网站
  • 高端企业网站开发网站需要第三方登录怎么做
  • 滨州注册公司网站优化用户体验
  • 网站功能建设与栏目划分公司网站怎么建
  • dw做的网站后台是什么好看的网站建设
  • 网站开发中点赞怎么做到的怎么把视频弄成一个链接网址
  • 上海做网站多少钱网站统计工具是什么意思
  • 呼和浩特做网站的公司网络规划设计师资料及视频教程
  • 网站开发项目规划如何做免费域名网站
  • 做网站需要基础吗诸塈市建设局网站
  • 十大免费ae模板网站住房城乡建设部招投标网站
  • 网站建设采购项目合同书广州网站设计企业
  • 徐州泉山区建设局网站长沙系统开发公司
  • 学校建网站青岛网站搭建
  • 北京网站建设公司收购360免费体育直播