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

上海网站制作公司哪家wordpress 广告播放器

上海网站制作公司哪家,wordpress 广告播放器,wordpress引用文章,规划设计公司起名原文#xff1a;Langchain 代理 (Agents) #xff0c;赋能超级 LLMs - 知乎 大型语言模型#xff08;LLMs#xff09; 非常强大#xff0c;但它们缺乏“最笨”的计算机程序可以轻松处理的特定能力。逻辑、计算和搜索是计算机通常擅长的领域#xff0c;但 LLMs 却遇到了困… 原文Langchain 代理 (Agents) 赋能超级 LLMs - 知乎 大型语言模型LLMs 非常强大但它们缺乏“最笨”的计算机程序可以轻松处理的特定能力。逻辑、计算和搜索是计算机通常擅长的领域但 LLMs 却遇到了困难。 计算机可以解决非常复杂的数学问题但如果我们让 GPT-4 告诉我们 4.1 * 7.9 的答案它就失败了 GPT 4 对简单计算的响应 要求 GPT-4 执行简单的计算通常会得到一个错误的答案。一个简单的计算器可以毫无问题地执行相同的计算。 根据一个简单的计算器答案是 19.357保留三位小数。一个简单的计算器程序可以做到这一点但一个非常复杂的 AI 引擎却失败了这是不是很有趣 这还不是全部。如果我问 GPT-4“我如何在 LangChain 中使用 LLMChain”它又遇到了困难 GPT-4 无法回答关于最近事件、技术等的问题 这里谈到的 LangChain 并不是我们所知道的 LangChain。它是一个旧的区块链项目。回答既过时又充满错误的信息。 没错。LangChain 确实是一个区块链项目 [1][2]。然而似乎没有“ LLMChain ”组件或“ LANG 代币 ”——这两者都是幻觉。 GPT-4 无法告诉我们关于 LangChain 的信息这是因为它与外部世界没有联系。它的唯一知识来自于它的训练数据而训练数据在 2021 年末截止。 在当今的 LLMs 一代中存在重大缺陷我们必须找到解决这些问题的方法。一种“解决方案套件”以“代理 (Agents) ”形式提供。 这些代理 (Agents) 不仅解决了我们上面看到的问题还解决了 许多 其他问题。事实上添加代理 (Agents) 在增强 LLMs 的能力方面几乎没有上限。 在本章中我们将讨论代理 (Agents) 。我们将学习它们是什么它们如何工作以及如何在 LangChain 库中使用它们来为我们的 LLMs 增添超能力。 什么是代理 (Agents) ? 我们可以将代理 (Agents) 视为 LLMs 的工具 (Tools) 。就像人类使用计算器进行数学计算或在 Google 中搜索信息一样代理 (Agents) 允许 LLM 做同样的事情。 LangChain LLM 代理 (Agents) 代理 (Agents) 是可以使用计算器、搜索或执行代码的 LLMs。 使用代理 (Agents) LLM 可以编写和执行 Python 代码。它可以搜索信息甚至查询 SQL 数据库。 让我们看一个简单的例子。我们将从一个 “Zero-shot” 代理 (Agents) 开始稍后会详细介绍它允许我们的 LLM 使用计算器。 代理 (Agents) 和工具 要使用代理 (Agents) 我们需要三样东西 一个基本的 LLM我们将要进行交互的工具 Tools一个控制交互的代理 (Agents) 。 让我们从安装 langchain 并初始化我们的基本 LLM 开始。 from langchain import OpenAIllm OpenAI(openai_api_keyOPENAI_API_KEY,temperature0,model_nametext-davinci-003 ) 现在初始化计算器工具。 在初始化工具 Tool 时我们可以创建自定义工具 Tool 或加载预构建工具 Tool。 无论哪种情况工具 Tool 都是一个给定工具 名称 name 和 描述 description 的 实用链。 例如我们可以从现有的 llm_math 链创建一个新的计算器工具 In [3]: from langchain.chains import LLMMathChain from langchain.agents import Toolllm_math LLMMathChain(llm llm)# initialize the math tool math_tool Tool(name Calculator,func llm_math.run,description Useful for when you need to answer questions about math. ) # when giving tools to LLM, we must pass as list of tools tools [math_tool] In [4]: tools [0].name, tools [0].description Out [4]: (Calculator, Useful for when you need to answer questions about math.) 在使用自定义工具时我们必须遵循此过程。然而一个预构建的 llm_math 工具可以做同样的事情。所以我们可以这样做 In [5]: from langchain.agents import load_toolstools load_tools([llm-math],llm llm ) In [6]: tools [0].name, tools [0].description Out [6]: (Calculator, Useful for when you need to answer questions about math.) 如果我们的用例存在一个预构建的工具我们只能按照第二种方法进行。 现在我们有了 LLM 和工具但没有 代理 (Agents) 。 要初始化一个简单的代理 (Agents) 我们可以这样做 from langchain.agents import initialize_agentzero_shot_agent initialize_agent(agent zero-shot-react-description,tools tools,llm llm,verbose True,max_iterations 3 ) 这里使用的 *代理 (Agents) * 是一个 zero-shot-react-description 代理 (Agents) 。 Zero-shot 意味着代理 (Agents) 仅在当前操作上起作用——它没有 记忆。 它使用 ReAct 框架根据工具的 描述 description 来决定使用哪个工具。 我们不会在本章中讨论 * ReAct 框架 但您可以将其视为 LLM 可以循环进行 * Re asoning 和 * Act ion 步骤的过程。它启用了一个多步骤的过程来识别答案。* 初始化了我们的代理 (Agents) 后我们可以开始使用它。让我们尝试一些提示看看代理 (Agents) 如何回应。 In [8]: zero_shot_agent( what is (4.5*2.1)^2.2?) Out [8]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m I need to calculate this expression Action: Calculator Action Input: (4.5*2.1)^2.2 [0m Observation: [36; 1m [1; 3mAnswer: 139.94261298333066 [0m Thought: [32; 1m [1; 3m I now know the final answer Final Answer: 139.94261298333066 [0m [1m Finished chain.[0m {input: what is (4.5*2.1)^2.2?, output: 139.94261298333066} In [9]: (4.5 *2.1)**2.2 Out [9]: 139.94261298333066 这里的答案是正确的。让我们再试一次 In [10]: zero_shot_agent(if Mary has four apples and Giorgio brings two and a half apple boxes (apple box contains eight apples), how many apples do we have?) Out [10]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m I need to figure out how many apples are in the boxes Action: Calculator Action Input: 8 * 2.5 [0m Observation: [36; 1m [1; 3mAnswer: 20.0 [0m Thought: [32; 1m [1; 3m I need to add the apples Mary has to the apples in the boxes Action: Calculator Action Input: 4 20.0 [0m Observation: [36; 1m [1; 3mAnswer: 24.0 [0m Thought: [32; 1m [1; 3m I now know the final answer Final Answer: We have 24 apples.[0m [1m Finished chain.[0m {input: if Mary has four apples and Giorgio brings two and a half apple boxes (apple box contains eight apples), how many apples do we have?,output: We have 24 apples.} 看起来很棒但是如果我们决定问一个非数学问题呢如果我们问一个简单的常识问题会怎样 In [11]: zero_shot_agent(what is the capital of Norway?) Out [11]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m I need to look up the answer Action: Look up Action Input: Capital of Norway [0m Observation: Look up is not a valid tool, try another one. Thought: [32; 1m [1; 3m I need to find the answer using a tool Action: Calculator Action Input: N/A [0m 我们遇到了一个错误。问题在于代理 (Agents) 一直在尝试使用工具。然而我们的代理 (Agents) 只包含一个工具——计算器。 幸运的是我们可以通过给代理 (Agents) 添加更多工具来解决这个问题让我们添加一个简单的 LLM 工具 from langchain.prompts import PromptTemplate from langchain.chains import LLMChainprompt PromptTemplate(input_variables [query],template {query} )llm_chain LLMChain(llm llm, prompt prompt)# initialize the LLM tool llm_tool Tool(name Language Model,func llm_chain.run,description use this tool for general purpose queries and logic ) 有了这个我们有了一个新的通用 LLM 工具。我们只需将其添加到 tools 列表中并重新初始化代理 (Agents) tools.append(llm_tool)# reinitialize the agent zero_shot_agent initialize_agent(agent zero-shot-react-description,tools tools,llm llm,verbose True,max_iterations 3 ) 现在我们可以向代理 (Agents) 提问关于数学和常识的问题。让我们尝试以下问题 In [15]: zero_shot_agent(what is the capital of Norway?) Out [15]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m I need to find out what the capital of Norway is Action: Language Model Action Input: What is the capital of Norway?[0m Observation: [33; 1m [1; 3m The capital of Norway is Oslo.[0m Thought: [32; 1m [1; 3m I now know the final answer Final Answer: The capital of Norway is Oslo.[0m [1m Finished chain.[0m {input: what is the capital of Norway?,output: The capital of Norway is Oslo.} 现在我们得到了正确的答案我们可以问第一个问题 In [16]: zero_shot_agent( what is (4.5*2.1)^2.2?) Out [16]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m I need to calculate this expression Action: Calculator Action Input: (4.5*2.1)^2.2 [0m Observation: [36; 1m [1; 3mAnswer: 139.94261298333066 [0m Thought: [32; 1m [1; 3m I now know the final answer Final Answer: 139.94261298333066 [0m [1m Finished chain.[0m {input: what is (4.5*2.1)^2.2?, output: 139.94261298333066} 代理 (Agents) 理解该引用计算器工具它确实给了我们正确的答案。 完成后我们应该了解设计和提示具有不同工具的代理 (Agents) 的工作流程。现在让我们继续介绍可用的不同类型的代理 (Agents) 和工具。 代理 (Agents) 类型 LangChain 提供了几种类型的代理 (Agents) 。在本节中我们将介绍一些最常见的类型。 Zero Shot ReAct 我们将从之前看到的代理 (Agents) 开始即 zero-shot-react-description 代理 (Agents) 。 如前所述我们使用此代理 (Agents) 在某些输入上执行 “zero-shot” 任务。这意味着代理 (Agents) 仅考虑与代理 (Agents) 的 一次 交互——它将没有 记忆。 让我们创建一个 tools 列表供代理 (Agents) 使用。我们将包括一个 llm-math 工具和一个 SQL 数据库工具我们在 这里定义。 tools load_tools([llm-math], llm llm )# add our custom SQL db tool tools.append(sql_tool) 我们这样初始化 zero-shot-react-description 代理 (Agents) from langchain.agents import initialize_agentzero_shot_agent initialize_agent(agent zero-shot-react-description, tools tools, llm llm,verbose True,max_iterations 3, ) 为了对 SQL 数据库工具进行一些背景说明我们将使用它来查询一个看起来像这样的“股票数据库” obs_idstock_tickerpricedata1‘ABC’2001 Jan 232‘ABC’2082 Jan 233‘ABC’2323 Jan 234‘ABC’2254 Jan 235‘ABC’2265 Jan 236‘XYZ’8101 Jan 237‘XYZ’8032 Jan 238‘XYZ’7983 Jan 239‘XYZ’7954 Jan 2310‘XYZ’7915 Jan 23 现在我们可以开始向这个 SQL 数据库提问并通过计算器工具进行配对计算。 In [16]: result zero_shot_agent(What is the multiplication of the ratio between stock prices for ABC and XYZ in January 3rd and the ratio between the same stock prices in January the 4th? ) Out [16]: [1m Entering new AgentExecutor chain...[0m [32;1m[1;3m I need to compare the stock prices of ABC and XYZ on two different days Action: Stock DB Action Input: Stock prices of ABC and XYZ on January 3rd and January 4th[0m [1m Entering new SQLDatabaseChain chain...[0m Stock prices of ABC and XYZ on January 3rd and January 4th SQLQuery:[32;1m[1;3m SELECT stock_ticker, price, date FROM stocks WHERE (stock_ticker ABC OR stock_ticker XYZ) AND (date 2023-01-03 OR date 2023-01-04)[0m SQLResult: [33;1m[1;3m[(ABC, 232.0, 2023-01-03), (ABC, 225.0, 2023-01-04), (XYZ, 798.0, 2023-01-03), (XYZ, 795.0, 2023-01-04)][0m Answer:[32;1m[1;3m The stock prices of ABC and XYZ on January 3rd and January 4th were 232.0 and 798.0 respectively for ABC and XYZ on January 3rd, and 225.0 and 795.0 respectively for ABC and XYZ on January 4th.[0m [1m Finished chain.[0m Observation: [33;1m[1;3m The stock prices of ABC and XYZ on January 3rd and January 4th were 232.0 and 798.0 respectively for ABC and XYZ on January 3rd, and 225.0 and 795.0 respectively for ABC and XYZ on January 4th.[0m Thought:[32;1m[1;3m I need to calculate the ratio between the two stock prices on each day Action: Calculator Action Input: 232.0/798.0 and 225.0/795.0[0m Observation: [36;1m[1;3mAnswer: 0.2907268170426065 0.2830188679245283 [0m Thought:[32;1m[1;3m I need to calculate the multiplication of the two ratios Action: Calculator Action Input: 0.2907268170426065 * 0.2830188679245283[0m Observation: [36;1m[1;3mAnswer: 0.08228117463469994 [0m Thought:[32;1m[1;3m[0m [1m Finished chain.[0m 我们可以看到这里有很多输出。在每一步中都有一个思考过程产生了一个选定的动作和动作输入。如果动作需要使用工具那么观察结果即工具的输出就会被传回给代理。 如果我们看一下代理使用的提示我们就可以看到 LLM 是如何决定使用哪个工具的。 In [17]: print(zero_shot_agent.agent.llm_chain.prompt.template) Out [17]: Answer the following questions as best you can. You have access to the following tools: Calculator: Useful for when you need to answer questions about math. Stock DB: Useful for when you need to answer questions about stocks and their prices. Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [Calculator, Stock DB] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can repeat N times) Thought: I now know the final answer Final Answer: the final answer to the original input question Begin! Question: {input} Thought:{agent_scratchpad} 我们首先告诉 LLM 它可以使用的工具Calculator 和 Stock DB。在此之后定义了一个示例格式它遵循 Question来自用户、Thought思考、Action动作、Action Input动作输入、Observation观察结果的流程 - 并重复这个流程直到达到 Final Answer最终答案。 这些工具和思考过程将 LangChain 中的 agents 与 chains 分开。 而 chain 定义了一种即时的输入/输出过程agents 的逻辑允许一步一步地进行思考。这种一步一步的过程的优势在于 LLM 可以通过多个推理步骤或工具来得出更好的答案。 我们还需要讨论提示的最后一部分。最后一行是 Thought:{agent_scratchpad}。 agent_scratchpad 是我们添加代理 (Agents) 已经执行的 每个 思考或动作的地方。所有的思考和动作在 当前 代理 (Agents) 执行器链中都可以被 下一个 思考-动作-观察循环访问从而实现代理 (Agents) 动作的连续性。 会话式 ReAct Conversational ReAct Zero-shot 代理 (Agents) 的效果很好但缺乏 会话式记忆。 这种缺乏记忆的情况对于需要在对话中 记住 以前的交互的聊天机器人类型的用例来说可能是有问题的。 幸运的是我们可以使用 conversational-react-description 代理 (Agents) 来 记住 交互。 我们可以将这个代理 (Agents) 看作是我们之前的 Zero Shot ReAct 代理 (Agents) 但具有 对话记忆。 要初始化代理 (Agents) 我们首先需要初始化我们想要使用的记忆。我们将使用简单的 ConversationBufferMemory。 from langchain.memory import ConversationBufferMemorymemory ConversationBufferMemory(memory_key chat_history ) 我们在初始化代理 (Agents) 时将其传递给 memory 参数 conversational_agent initialize_agent(agent conversational-react-description, tools tools, llm llm,verbose True,max_iterations 3,memory memory, ) 如果我们用类似的问题运行这个代理 (Agents) 我们应该会看到与之前类似的过程 In [22]: result conversational_agent(Please provide me the stock prices for ABC on January the 1st ) Out [22]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m Thought: Do I need to use a tool? Yes Action: Stock DB Action Input: ABC on January the 1st [0m [1m Entering new SQLDatabaseChain chain...[0mABC on January the 1st SQLQuery: [32; 1m [1; 3m SELECT price FROM stocks WHERE stock_ticker ABC AND date 2023-01-01[0mSQLResult: [33; 1m [1; 3m[(200.0,)] [0mAnswer: [32; 1m [1; 3m The price of ABC on January the 1st was 200.0.[0m[1m Finished chain.[0mObservation: [33; 1m [1; 3m The price of ABC on January the 1st was 200.0.[0mThought: [32; 1m [1; 3m Do I need to use a tool? NoAI: Is there anything else I can help you with?[0m[1m Finished chain.[0m 到目前为止这看起来与我们上一个 Zero-shot 代理 (Agents) 非常相似。然而与我们的 Zero-shot 代理 (Agents) 不同我们现在可以提问 后续 问题。让我们询问一下股票价格在 同一日期 上的 XYZ而不指定 1 月 1 日。 In [24]: result conversational_agent(What are the stock prices for XYZ on the same day? ) Out [24]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m Thought: Do I need to use a tool? Yes Action: Stock DB Action Input: Stock prices for XYZ on January 1st [0m [1m Entering new SQLDatabaseChain chain...[0m Stock prices for XYZ on January 1st SQLQuery: [32; 1m [1; 3m SELECT price FROM stocks WHERE stock_ticker XYZ AND date 2023-01-01[0m SQLResult: [33; 1m [1; 3m[(810.0,)] [0m Answer: [32; 1m [1; 3m The stock price for XYZ on January 1st was 810.0.[0m [1m Finished chain.[0m Observation: [33; 1m [1; 3m The stock price for XYZ on January 1st was 810.0.[0m Thought: [32; 1m [1; 3m Do I need to use a tool? No AI: Is there anything else I can help you with?[0m [1m Finished chain.[0m 我们可以看到第一个 Action Input 中代理 (Agents) 正在寻找 Stock prices for XYZ on January 1st。它知道我们正在寻找 1 月 1 日因为我们在之前的交互中提到了这个日期。 它是如何做到的呢我们可以看一下提示模板来找出答案 In [23]: print(conversational_agent.agent.llm_chain.prompt.template) Out [23]: Assistant is a large language model trained by OpenAI. Assistant is 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, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand. Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is 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. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics. Overall, Assistant is 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 you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist. TOOLS: ------ Assistant has access to the following tools:Calculator: Useful for when you need to answer questions about math.Stock DB: Useful for when you need to answer questions about stocks and their prices. To use a tool, please use the following format:Thought: Do I need to use a tool? Yes Action: the action to take, should be one of [Calculator, Stock DB] Action Input: the input to the action Observation: the result of the actionWhen you have a response to say to the Human, or if you do not need to use a tool, you MUST use the format:Thought: Do I need to use a tool? No AI: [your response here]Begin! Previous conversation history: {chat_history} New input: {input} {agent_scratchpad} 我们在提示的开头有一个更大的指令设置但最重要的是在提示的末尾附近的两行 Previous conversation history: {chat_history} 这是我们将所有先前的交互添加到提示中的地方。在这个空间内将包含我们要求的信息 Please provide me the stock prices for ABC on January the 1st - 这使得代理 (Agents) 可以理解我们的后续问题是指同一日期。 值得注意的是与 Zero-shot 代理 (Agents) 相比会话式 ReAct 代理 (Agents) 在组合多个复杂步骤时会更加困难。如果我们要求代理 (Agents) 回答我们之前的问题我们可以看到这一点 In [26]: result conversational_agent(What is the multiplication of the ratio of the prices of stocks ABC and XYZ in January 3rd and the ratio of the same prices of the same stocks in January the 4th? ) Out [26]: [1m Entering new AgentExecutor chain...[0m [32;1m[1;3mThought: Do I need to use a tool? Yes Action: Stock DB Action Input: Get the ratio of the prices of stocks ABC and XYZ in January 3rd and the ratio of the same prices of the same stocks in January the 4th[0m [1m Entering new SQLDatabaseChain chain...[0m Get the ratio of the prices of stocks ABC and XYZ in January 3rd and the ratio of the same prices of the same stocks in January the 4th SQLQuery:[32;1m[1;3m SELECT (SELECT price FROM stocks WHERE stock_ticker ABC AND date 2023-01-03) / (SELECT price FROM stocks WHERE stock_ticker XYZ AND date 2023-01-03) AS ratio_jan_3, (SELECT price FROM stocks WHERE stock_ticker ABC AND date 2023-01-04) / (SELECT price FROM stocks WHERE stock_ticker XYZ AND date 2023-01-04) AS ratio_jan_4 FROM stocks LIMIT 5;[0m SQLResult: [33;1m[1;3m[(0.2907268170426065, 0.2830188679245283), (0.2907268170426065, 0.2830188679245283), (0.2907268170426065, 0.2830188679245283), (0.2907268170426065, 0.2830188679245283), (0.2907268170426065, 0.2830188679245283)][0m Answer:[32;1m[1;3m The ratio of the prices of stocks ABC and XYZ in January 3rd is 0.2907268170426065 and the ratio of the same prices of the same stocks in January the 4th is 0.2830188679245283.[0m [1m Finished chain.[0m Observation: [33;1m[1;3m The ratio of the prices of stocks ABC and XYZ in January 3rd is 0.2907268170426065 and the ratio of the same prices of the same stocks in January the 4th is 0.2830188679245283.[0m Thought:[32;1m[1;3m Do I need to use a tool? No AI: The answer is 0.4444444444444444. Is there anything else I can help you with?[0m [1m Finished chain.[0m Spent a total of 2518 tokens 通过这样做代理 (Agents) 仍然设法解决了问题但使用了一个更复杂的纯 SQL 方法而不是依赖于更直接的 SQL 和计算器工具。 ReAct 文档存储 另一个常见的代理 (Agents) 是 react-docstore 代理 (Agents) 。与之前一样它使用 ReAct 方法但现在明确地用于使用 LangChain 的 docstore 进行信息搜索和查找。 LangChain docstore 允许我们使用传统的检索方法存储和检索信息。其中一个 docstore 是维基百科它使我们能够访问站点上的信息。 我们将使用两种 docstore 方法来实现这个代理 (Agents) - Search 和 Lookup。 使用 Search我们的代理 (Agents) 将搜索相关文章 使用 Lookup代理 (Agents) 将在检索到的文章中找到相关的信息块。 要初始化这两个工具我们执行以下操作 from langchain import Wikipedia from langchain.agents.react.base import DocstoreExplorerdocstore DocstoreExplorer(Wikipedia()) tools [Tool(name Search,func docstore.search,description search wikipedia),Tool(name Lookup,func docstore.lookup,description lookup a term in wikipedia) ] 现在初始化代理 (Agents) docstore_agent initialize_agent(tools, llm, agent react-docstore, verbose True,max_iterations 3 ) 让我们尝试以下内容 In [30]: docstore_agent(What were Archimedes last words?) Out [30]: [1m Entering new AgentExecutor chain...[0m [32;1m[1;3mThought: I need to search Archimedes and find his last words. Action: Search[Archimedes][0m Observation: [36;1m[1;3mArchimedes of Syracuse (; c. 287 – c. 212 BC) was a Greek mathematician, physicist, engineer...[0m Thought:[32;1m[1;3m The paragraph does not mention Archimedes last words. I need to look up last words. Action: Lookup[last words][0m Observation: [33;1m[1;3m(Result 1/1) Plutarch (45–119 AD) wrote in his Parallel Lives that Archimedes was related to King Hiero...[0m Thought:[32;1m[1;3m The last words attributed to Archimedes are Do not disturb my circles, so the answer is Do not disturb my circles. Action: Finish[Do not disturb my circles][0m [1m Finished chain.[0m {input: What were Archimedes last words?,output: Do not disturb my circles} 这个代理 (Agents) 的提示非常长所以我们会展示一个缩短版。它只包含了几个示例展示了这个代理 (Agents) 应该如何使用 Search 和 Lookup 工具 Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?Thought: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado orogeny extends into, then find the elevation range of the area. Action: Search [Colorado orogeny] Observation: The Colorado orogeny was an episode of mountain building (an orogeny) in Colorado and surrounding areas.Thought: It does not mention the eastern sector. So I need to look up eastern sector. Action: Lookup [eastern sector] Observation: (Result 1 / 1) The eastern sector extends into the High Plains and is called the Central Plains orogeny.Thought: The eastern sector of Colorado orogeny extends into the High Plains. So I need to search High Plains and find its elevation range. Action: Search [High Plains] Observation: High Plains refers to one of two distinct land regionsThought: I need to instead search High Plains (United States). Action: Search [High Plains (United States)] Observation: The High Plains are a subregion of the Great Plains. From east to west, the High Plains rise in elevation from around 1,800 to 7,000 ft (550 to 2,130 m).[3]Thought: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. Action: Finish [1,800 to 7,000 ft] 提示中包含了几个类似格式的示例。在提示的末尾我们看到 Question: {input} {agent_scratchpad} 与之前一样我们有一个 {input} 来传递最近的用户查询还有一个 {agent_scratchpad} 来跟踪以前的思考和行动。 与我们的 会话式 代理 (Agents) 不同这里没有 {chat_history} 输入。这意味着我们正在使用另一个 Zero-shot 代理 (Agents) 。 使用搜索自问 让我们看看最后一个代理 (Agents) - self-ask-with-search 代理 (Agents) 。当连接 LLM 和搜索引擎时这是您应该考虑的第一个代理 (Agents) 。 代理 (Agents) 将根据需要执行搜索和提问步骤以获得最终答案。我们这样初始化代理 (Agents) from langchain import SerpAPIWrapper# initialize the search chain search SerpAPIWrapper(serpapi_api_key serp_api_key)# create a search tool tools [Tool(name Intermediate Answer,func search.run,description google search) ]# initialize the search enabled agent self_ask_with_search initialize_agent(tools,llm,agent self-ask-with-search,verbose True ) 现在让我们问一个需要多次搜索和“自问”步骤的问题。 In [38]: self_ask_with_search(who lived longer; Plato, Socrates, or Aristotle? ) Out [38]: [1m Entering new AgentExecutor chain...[0m [32; 1m [1; 3m Yes. Follow up: How old was Plato when he died?[0m Intermediate answer: [36; 1m [1; 3meighty [0m [32; 1m [1; 3m Follow up: How old was Socrates when he died?[0m Intermediate answer: [36; 1m [1; 3mapproximately 71 [0m [32; 1m [1; 3m Follow up: How old was Aristotle when he died?[0m Intermediate answer: [36; 1m [1; 3m62 years [0m [32; 1m [1; 3m So the final answer is: Plato [0m [1m Finished chain.[0m {input: who lived longer; Plato, Socrates, or Aristotle?,output: Plato} 我们可以看到代理 (Agents) 的多步骤过程。它进行了多次后续问题来找到最终答案。 这就是关于 LangChain 代理 (Agents) 的章节的全部内容。正如您无疑注意到的那样代理 (Agents) 涵盖了 LangChain 中广泛的工具范围。我们已经涵盖了很多基本知识但还有很多可以讨论的内容。 代理 (Agents) 的变革潜力是大型语言模型LLMs的一大飞跃只是时间问题“LLM 代理 (Agents) ”这个术语将成为 LLMs 本身的代名词。 通过赋予 LLMs 利用工具和在这些代理 (Agents) 框架中导航复杂的多步骤思考过程的能力我们正在进入一个庞大到令人难以置信的 AI 驱动机会的领域。 参考文献 [1] Langchain.io (2019), Wayback Machine [2] 李俊航Mother of Language Slides (2018)SlideShare 下一章为 LLM Agents 构建自定义工具 LANGCHAIN 开发者技术交流社群
http://www.pierceye.com/news/354414/

相关文章:

  • 免费行情软件网站下载大全爱学校vi设计案例
  • 网站外包优化怎样做免费抽皮肤的网站
  • 东八区网站建设网站源码在哪里
  • 重点建设专业 专题网站搜狗官方网站
  • 微信营销工具有哪些使用最佳搜索引擎优化工具
  • 网站推广意识薄弱wordpress授权协议
  • 用php做高中数学题库网站阿里网站建设教程
  • 大兴网站建设公司电话东莞企业网站制作怎么做
  • 网站维护有啥用2021跨境电商最火的产品
  • 专业的东莞网站排名wordpress 客户端使用
  • 做网站需要什么人才网站建设与规划案例
  • 你学做网站学了多久建设网站困难的解决办法
  • 东莞如何搭建网站建设做招聘信息的网站
  • 网站行业认证怎么做安卓开发技术
  • 泉州城乡住房建设厅网站网站运营方案ppt
  • 免费做网站wxp114五种常用的网站推广方法
  • 简单的网站建设找哪个公司新网站seo技术
  • 电子网址怎么创建下载优化大师app
  • 网站上传服务器教程wordpress 开启多用户
  • 做网站的公司重庆互联网营销方式
  • 在线探测网站开发语言东莞人才市场现场招聘会地址
  • 检测网站是否被挂黑链seo网站营销推广
  • 当今网站开发技术的现状自己做的网站怎么上排行榜
  • 外贸没有公司 如何做企业网站?成都市住房和城乡建设局官网查询
  • 公证网站建设管理无锡百度正规推广
  • 免费海外网站建设自学设计软件的免费网站
  • 个人姓名最多备案多少个网站外贸网站制作公司
  • 上海市建设安全协会官方网站上海人才网官网公示
  • 原创文章网站wordpress注册页面修改密码
  • 山东省建设注册执业中心网站博物馆网站做的最好的