{"id":53064,"date":"2024-12-03T14:15:27","date_gmt":"2024-12-03T06:15:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53064\/"},"modified":"2024-12-03T14:15:27","modified_gmt":"2024-12-03T06:15:27","slug":"%e4%bd%bf%e7%94%a8-nodejs-%e5%88%9b%e5%bb%ba-react-ai-%e4%bb%a3%e7%90%86%ef%bc%88%e7%bb%b4%e5%9f%ba%e7%99%be%e7%a7%91%e6%90%9c%e7%b4%a2%ef%bc%89en","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53064\/","title":{"rendered":"\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241126\/17325932636745466f2b418.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en\u63d2\u56fe\" alt=\"\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en\u63d2\u56fe\" \/><\/p>\n<h2> \u4ecb\u7ecd <\/h2>\n<p>\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u80fd\u591f\u641c\u7d22\u7ef4\u57fa\u767e\u79d1\u5e76\u6839\u636e\u6536\u96c6\u5230\u7684\u4fe1\u606f\u56de\u7b54\u95ee\u9898\u7684\u4eba\u5de5\u667a\u80fd\u4ee3\u7406\u3002 <br \/> \u8be5 react\uff08\u63a8\u7406\u548c\u884c\u52a8\uff09\u4ee3\u7406\u4f7f\u7528 google generative ai api \u6765\u5904\u7406\u67e5\u8be2\u5e76\u751f\u6210\u54cd\u5e94\u3002 <\/p>\n<p>\u6211\u4eec\u7684\u4ee3\u7406\u5c06\u80fd\u591f\uff1a<\/p>\n<ol>\n<li>\u5728\u7ef4\u57fa\u767e\u79d1\u4e0a\u641c\u7d22\u76f8\u5173\u4fe1\u606f\u3002<\/li>\n<li>\u4ece\u7ef4\u57fa\u767e\u79d1\u9875\u9762\u4e2d\u63d0\u53d6\u7279\u5b9a\u90e8\u5206\u3002<\/li>\n<li>\u5bf9\u6536\u96c6\u5230\u7684\u4fe1\u606f\u8fdb\u884c\u5206\u6790\u5e76\u5236\u5b9a\u56de\u590d\u3002<\/li>\n<\/ol>\n<h2> [2] \u4ec0\u4e48\u662freact\u4ee3\u7406\uff1f <\/h2>\n<p>react agent \u662f\u4e00\u79cd\u9075\u5faa\u53cd\u5c04-\u64cd\u4f5c\u5faa\u73af\u7684\u7279\u5b9a\u7c7b\u578b\u7684\u4ee3\u7406\u3002\u5b83\u6839\u636e\u53ef\u7528\u4fe1\u606f\u548c\u53ef\u4ee5\u91c7\u53d6\u7684\u64cd\u4f5c\u6765\u53cd\u6620\u5f53\u524d\u4efb\u52a1\uff0c\u7136\u540e\u51b3\u5b9a\u91c7\u53d6\u4ec0\u4e48\u64cd\u4f5c\u6216\u662f\u5426\u5b8c\u6210\u4efb\u52a1\u3002<\/p>\n<h2> [3] \u89c4\u5212\u4ee3\u7406 <\/h2>\n<h3> 3.1 \u6240\u9700\u5de5\u5177 <\/h3>\n<ul>\n<li>node.js<\/li>\n<li>\u7528\u4e8e http \u8bf7\u6c42\u7684 axios \u5e93<\/li>\n<li>google \u751f\u6210\u5f0f ai api (gemini-1.5-flash)<\/li>\n<li>\u7ef4\u57fa\u767e\u79d1 api<\/li>\n<\/ul>\n<h3> 3.2 \u4ee3\u7406\u7ed3\u6784 <\/h3>\n<p>\u6211\u4eec\u7684 react agent \u5c06\u5177\u6709\u4e09\u4e2a\u4e3b\u8981\u72b6\u6001\uff1a<\/p>\n<ol>\n<li>\u601d\u60f3\uff08\u53cd\u601d\uff09<\/li>\n<li>\u884c\u52a8\uff08\u6267\u884c\uff09<\/li>\n<li>\u56de\u7b54\uff08\u56de\u590d\uff09<\/li>\n<\/ol>\n<h3> 3.3 \u601d\u60f3\u72b6\u6001 <\/h3>\n<p>\u601d\u8003\u72b6\u6001\u662freactagent\u5bf9\u6536\u96c6\u5230\u7684\u4fe1\u606f\u8fdb\u884c\u53cd\u601d\u5e76\u51b3\u5b9a\u4e0b\u4e00\u6b65\u5e94\u8be5\u505a\u4ec0\u4e48\u7684\u65f6\u523b\u3002<\/p>\n<pre>async thought() {\n    \/\/ ...\n}\n<\/pre>\n<h3> 3.4 \u52a8\u4f5c\u72b6\u6001\uff08action\uff09 <\/h3>\n<p>\u5728\u52a8\u4f5c\u72b6\u6001\u4e0b\uff0c\u4ee3\u7406\u6839\u636e\u5148\u524d\u7684\u60f3\u6cd5\u6267\u884c\u53ef\u7528\u529f\u80fd\u4e4b\u4e00\u3002<br \/> \u8bf7\u6ce8\u610f\uff0c\u6709\u884c\u52a8\uff08\u6267\u884c\uff09\u548c\u51b3\u5b9a\uff08\u54ea\u4e2a\u884c\u52a8\uff09\u3002<\/p>\n<pre>async action() {\n    \/\/ chama a decis\u00e3o\n    \/\/ executa a a\u00e7\u00e3o e retorna um actionresult\n}\n\nasync decideaction() {\n    \/\/ chama o llm com base no pensamento (reflex\u00e3o) para formatar e adequar a chamada de fun\u00e7\u00e3o.\n    \/\/ procure por um modo de fun\u00e7\u00e3o-ferramenta na [documenta\u00e7\u00e3o da api do google](https:\/\/ai.google.dev\/gemini-api\/docs\/function-calling)\n}\n<\/pre>\n<h2> [4] \u5b9e\u73b0\u4ee3\u7406 <\/h2>\n<p>\u8ba9\u6211\u4eec\u9010\u6b65\u6784\u5efa react agent\uff0c\u7a81\u51fa\u663e\u793a\u6bcf\u4e2a\u72b6\u6001\u3002<\/p>\n<h3> 4.1 \u521d\u59cb\u914d\u7f6e <\/h3>\n<p>\u9996\u5148\uff0c\u914d\u7f6e\u9879\u76ee\u5e76\u5b89\u88c5\u4f9d\u8d56\u9879\uff1a<\/p>\n<pre>mkdir projeto-agente-react\ncd projeto-agente-react\nnpm init -y\nnpm install axios dotenv @google\/generative-ai\n<\/pre>\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u521b\u5efa\u4e00\u4e2a.env\u6587\u4ef6\uff1a<\/p>\n<pre>google_ai_api_key=sua_chave_api_aqui\n<\/pre>\n<p>\u8fd9\u91cc\u6709\u514d\u8d39\u7684 api \u5bc6\u94a5<\/p>\n<h3> 4.2 \u89d2\u8272\u58f0\u660e <\/h3>\n<p>\u6b64\u6587\u4ef6\u662f node.js \u5c06\u7528\u6765\u6267\u884c\u5bf9\u7ef4\u57fa\u767e\u79d1\u7684 api \u8c03\u7528\u7684 javascript \u6587\u4ef6\u3002<br \/> \u6211\u4eec\u5728 functiondescription \u4e2d\u63cf\u8ff0\u4e86\u8be5\u6587\u4ef6\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u5185\u5bb9\u521b\u5efa tools.js\uff1a<\/p>\n<pre>const axios = require(\"axios\");\n\nclass tools {\n  static async wikipedia(q) {\n    try {\n      const response = await axios.get(\"https:\/\/pt.wikipedia.org\/w\/api.php\", {\n        params: {\n          action: \"query\",\n          list: \"search\",\n          srsearch: q,\n          srwhat: \"text\",\n          format: \"json\",\n          srlimit: 4,\n        },\n      });\n\n      const results = await promise.all(\n        response.data.query.search.map(async (searchresult) =&gt; {\n          const sectionresponse = await axios.get(\n            \"https:\/\/pt.wikipedia.org\/w\/api.php\",\n            {\n              params: {\n                action: \"parse\",\n                pageid: searchresult.pageid,\n                prop: \"sections\",\n                format: \"json\",\n              },\n            },\n          );\n\n          const sections = object.values(\n            sectionresponse.data.parse.sections,\n          ).map((section) =&gt; `${section.index}, ${section.line}`);\n\n          return {\n            pagetitle: searchresult.title,\n            snippet: searchresult.snippet,\n            pageid: searchresult.pageid,\n            sections: sections,\n          };\n        }),\n      );\n\n      return results\n        .map(\n          (result) =&gt;\n            `snippet: ${result.snippet}\\npageid: ${result.pageid}\\nsections: ${json.stringify(result.sections)}`,\n        )\n        .join(\"\\n\\n\");\n    } catch (error) {\n      console.error(\"error fetching from wikipedia:\", error);\n      return \"error fetching data from wikipedia\";\n    }\n  }\n\n  static async wikipedia_with_pageid(pageid, sectionid) {\n    if (sectionid) {\n      const response = await axios.get(\"https:\/\/pt.wikipedia.org\/w\/api.php\", {\n        params: {\n          action: \"parse\",\n          format: \"json\",\n          pageid: parseint(pageid),\n          prop: \"wikitext\",\n          section: parseint(sectionid),\n          disabletoc: 1,\n        },\n      });\n      return object.values(response.data.parse?.wikitext ?? {})[0]?.substring(\n        0,\n        25000,\n      );\n    } else {\n      const response = await axios.get(\"https:\/\/pt.wikipedia.org\/w\/api.php\", {\n        params: {\n          action: \"query\",\n          pageids: parseint(pageid),\n          prop: \"extracts\",\n          exintro: true,\n          explaintext: true,\n          format: \"json\",\n        },\n      });\n      return object.values(response.data?.query.pages)[0]?.extract;\n    }\n  }\n}\n\nmodule.exports = tools;\n<\/pre>\n<h3> 4.3 \u521b\u5efareactagent.js\u6587\u4ef6 <\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u5185\u5bb9\u521b\u5efa reactagent.js\uff1a<\/p>\n<pre>require(\"dotenv\").config();\nconst { googlegenerativeai } = require(\"@google\/generative-ai\");\nconst tools = require(\".\/tools\");\n\nconst genai = new googlegenerativeai(process.env.google_ai_api_key);\n\nclass reactagent {\n  constructor(query, functions) {\n    this.query = query;\n    this.functions = new set(functions);\n    this.state = \"thought\";\n    this._history = [];\n    this.model = genai.getgenerativemodel({\n      model: \"gemini-1.5-flash\",\n      temperature: 1.8,\n    });\n  }\n\n  async run() {\n    this.pushhistory(`**tarefa: ${this.query} **`);\n    try {\n      return await this.step();\n    } catch (e) {\n      console.error(\"erro durante a execu\u00e7\u00e3o:\", e);\n      return \"desculpe, n\u00e3o consegui processar sua solicita\u00e7\u00e3o.\";\n    }\n  }\n\n  async step() {\n    const colors = {\n      reset: \"\\x1b[0m\",\n      yellow: \"\\x1b[33m\",\n      red: \"\\x1b[31m\",\n      cyan: \"\\x1b[36m\",\n    };\n    console.log(\"====================================\");\n    console.log(\n      `next movement: ${\n        this.state === \"thought\"\n          ? colors.yellow\n          : this.state === \"action\"\n            ? colors.red\n            : this.state === \"answer\"\n              ? colors.cyan\n              : colors.reset\n      }${this.state}${colors.reset}`,\n    );\n    console.log(`last movement: ${this.history[this.history.length - 1]}`);\n    console.log(\"====================================\");\n    switch (this.state) {\n      case \"thought\":\n        return await this.thought();\n        break;\n      case \"action\":\n        return await this.action();\n        break;\n      case \"answer\":\n        return await this.answer();\n    }\n  }\n\n  async thought() {\n    const funcoesdisponiveis = json.stringify(array.from(this.functions));\n    const contextohistorico = this.history.join(\"\\n\");\n    const prompt = `sua tarefa \u00e9 ${this.consulta}\no contexto posui todas as reflex\u00f5es que voc\u00ea fez at\u00e9 agora e os resultadoa\u00e7\u00e3o que coletou.\na\u00e7\u00f5esdispon\u00edveis s\u00e3o fun\u00e7\u00f5es que voc\u00ea pode chamar sempre que precisar de mais dados.\n\ncontexto: \"${contextohistorico}\" &lt;&lt;\n\na\u00e7\u00f5esdispon\u00edveis: \"${funcoesdisponiveis}\" &lt;&lt;\n\ntarefa: \"${this.consulta}\" &lt;&lt;\n\nreflita sobre sua tarefa usando o contexto, resultadoa\u00e7\u00e3o e a\u00e7\u00f5esdispon\u00edveis para encontrar seu pr\u00f3ximo_passo.\nimprima seu pr\u00f3ximo_passo com um pensamento ou finalize cumprindo sua tarefa caso tenha as informa\u00e7\u00f5es dispon\u00edveis`;\n\n    const thought = await this.promptmodel(prompt);\n    this.pushhistory(`\\n **${thought.trim()}**`);\n\n    if (\n      thought.tolowercase().includes(\"cumprida\") ||\n      thought.tolowercase().includes(\"cumpra\") ||\n      thought.tolowercase().includes(\"cumprindo\") ||\n      thought.tolowercase().includes(\"finalizar\") ||\n      thought.tolowercase().includes(\"finalizando\") ||\n      thought.tolowercase().includes(\"finalize\") ||\n      thought.tolowercase().includes(\"conclu\u00edda\")\n    ) {\n      this.state = \"answer\";\n    } else {\n      this.state = \"action\";\n    }\n    return this.step();\n  }\n\n  async action() {\n    const action = await this.decideaction();\n    this.pushhistory(`** a\u00e7\u00e3o: ${action} **`);\n    const result = await this.executefunctioncall(action);\n    this.pushhistory(`** resultadoa\u00e7\u00e3o: ${result} **`);\n    this.state = \"thought\";\n    return this.step();\n  }\n\n  async decideaction() {\n    const availablefunctions = json.stringify(array.from(this.functions));\n    const historycontext = this.history;\n    const prompt = `reflita sobre o pensamento, consulta e a\u00e7\u00f5es dispon\u00edveis\n\n    ${historycontext[historycontext.length - 2]}\n\n    pensamento &lt;&lt;&lt; ${historycontext[historycontext.length - 1]}\n\n    consulta: \"${this.query}\"\n\n    a\u00e7\u00f5es dispon\u00edveis: ${availablefunctions}\n\n    retorne apenas a fun\u00e7\u00e3o,par\u00e2metros separados por v\u00edrgula. exemplo: \"wikipedia,ronaldinho gaucho,1450\"`;\n\n    const decision = await this.promptmodel(prompt);\n    return decision.replace(\/`\/g, \"\").trim();\n  }\n\n  async answer() {\n    const historycontext = this.history.join(\"\\n\");\n    const prompt = `com base no seguinte contexto, forne\u00e7a uma resposta completa e detalhada para a tarefa: ${this.query}.\n\n    contexto:\n    ${historycontext}\n\n    tarefa: \"${this.query}\"`;\n\n    const finalanswer = await this.promptmodel(prompt);\n    return finalanswer;\n  }\n\n  async promptmodel(prompt) {\n    const result = await this.model.generatecontent(prompt);\n    const response = await result.response;\n    return response.text();\n  }\n\n  async executefunctioncall(functioncall) {\n    const [functionname, ...args] = functioncall.split(\",\");\n    const func = tools[functionname.trim()];\n    if (func) {\n      return await func.call(null, ...args);\n    }\n    throw new error(`fun\u00e7\u00e3o ${functionname} n\u00e3o encontrada`);\n  }\n\n  pushhistory(value) {\n    this._history.push(value);\n  }\n\n  get history() {\n    return this._history;\n  }\n}\n\nmodule.exports = reactagent;\n<\/pre>\n<h3> 4.4 \u8fd0\u884c\u4ee3\u7406\u5e76\u89e3\u91ca\u53ef\u7528\u5de5\u5177 (index.js) <\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u5185\u5bb9\u521b\u5efaindex.js\uff1a<\/p>\n<pre>const reactagent = require(\".\/reactagentptbr.js\");\n\nasync function main() {\n  const query = \"que clubes ronaldinho ga\u00facho jogou para?\";\n  \/\/ const query = \"quais os bairros de joinville?\";\n  \/\/ const query = \"qual a capital da fran\u00e7a?\";\n\n  const functions = [\n    [\n      \"wikipedia\",\n      \"params: query\",\n      \"busca sem\u00e2ntica na wikipedia api por pageid e sectionids &gt;&gt; \\n ex: pontos tur\u00edsticos de s\u00e3o paulo \\n s\u00e3o paulo \u00e9 uma cidade com muitos pontos tur\u00edsticos, pageid, sections : []\",\n    ],\n    [\n      \"wikipedia_with_pageid\",\n      \"params: pageid, sectionid\",\n      \"busca na wikipedia api usando pageid e sectionindex como parametros. \\n ex: 1500,1234 \\n informa\u00e7\u00f5es sobre a se\u00e7\u00e3o blablalbal\",\n    ],\n  ];\n\n  const agent = new reactagent(query, functions);\n  const result = await agent.run();\n  console.log(\"resultado do agente:\", result);\n}\n\nmain().catch(console.error);\n<\/pre>\n<h2> \u89d2\u8272\u63cf\u8ff0 <\/h2>\n<p>\u5c1d\u8bd5\u6dfb\u52a0\u65b0\u5de5\u5177\u6216\u529f\u80fd\u65f6\uff0c\u8bf7\u52a1\u5fc5\u5bf9\u5176\u8fdb\u884c\u826f\u597d\u63cf\u8ff0\u3002<br \/> \u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c\u8fd9\u5df2\u7ecf\u5b8c\u6210\u5e76\u5728\u8c03\u7528\u65b0\u5b9e\u4f8b\u65f6\u6dfb\u52a0\u5230\u6211\u4eec\u7684 reactagent \u7c7b\u4e2d\u3002<\/p>\n<pre>const functions = [\n    [\n        \"google\", \/\/ nomeDaFuncao\n        \"params: query\", \/\/ NomeDoPar\u00e2metroLocal\n        \"Pesquisa sem\u00e2ntica na API da Wikipedia por snippets, pageIds e sectionIds &gt;&gt; \\n ex: Quando o Brasil foi colonizado? \\n O Brasil foi colonizado em 1500, pageId, sections : []\", \/\/ breve explica\u00e7\u00e3o e exemplo (isso ser\u00e1 encaminhado para o LLM)\n    ]\n];\n<\/pre>\n<h2> [5] \u7ef4\u57fa\u767e\u79d1\u90e8\u5206\u5982\u4f55\u8fd0\u4f5c <\/h2>\n<p>\u4e0e\u7ef4\u57fa\u767e\u79d1\u7684\u4e92\u52a8\u5206\u4e24\u4e2a\u4e3b\u8981\u6b65\u9aa4\u5b8c\u6210\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u521d\u59cb\u641c\u7d22\uff08\u7ef4\u57fa\u767e\u79d1\u529f\u80fd\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u5411\u7ef4\u57fa\u767e\u79d1\u641c\u7d22 api \u53d1\u51fa\u8bf7\u6c42\u3002<\/li>\n<li>\u6700\u591a\u8fd4\u56de 4 \u4e2a\u4e0e\u67e5\u8be2\u76f8\u5173\u7684\u7ed3\u679c\u3002<\/li>\n<li>\u5bf9\u4e8e\u6bcf\u4e2a\u7ed3\u679c\uff0c\u641c\u7d22\u9875\u9762\u7684\u5404\u4e2a\u90e8\u5206\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8be6\u7ec6\u641c\u7d22\uff08wikipedia_with_pageid\u51fd\u6570\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u9875\u9762 id \u548c\u5206\u533a id \u641c\u7d22\u7279\u5b9a\u5185\u5bb9\u3002<\/li>\n<li>\u8fd4\u56de\u8bf7\u6c42\u90e8\u5206\u7684\u6587\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u6b64\u8fc7\u7a0b\u5141\u8bb8\u4ee3\u7406\u9996\u5148\u83b7\u5f97\u4e0e\u67e5\u8be2\u76f8\u5173\u7684\u4e3b\u9898\u7684\u6982\u8ff0\uff0c\u7136\u540e\u6839\u636e\u9700\u8981\u6df1\u5165\u5230\u7279\u5b9a\u90e8\u5206\u3002<\/p>\n<h2> [6] \u6267\u884c\u6d41\u7a0b\u793a\u4f8b <\/h2>\n<ol>\n<li>\u7528\u6237\u63d0\u95ee\u3002<\/li>\n<li>\u667a\u80fd\u4f53\u8fdb\u5165\u601d\u8003\u72b6\u6001\u5e76\u53cd\u601d\u95ee\u9898\u3002<\/li>\n<li>\u4ed6\u51b3\u5b9a\u641c\u7d22\u7ef4\u57fa\u767e\u79d1\u5e76\u8fdb\u5165 action \u72b6\u6001\u3002<\/li>\n<li>\u8fd0\u884c\u7ef4\u57fa\u767e\u79d1\u51fd\u6570\u5e76\u83b7\u53d6\u7ed3\u679c\u3002<\/li>\n<li>\u8fd4\u56dethought\u72b6\u6001\u53cd\u601d\u7ed3\u679c\u3002<\/li>\n<li>\u60a8\u53ef\u4ee5\u51b3\u5b9a\u5bfb\u627e\u66f4\u591a\u7ec6\u8282\u6216\u4e0d\u540c\u7684\u65b9\u6cd5\u3002<\/li>\n<li>\u6839\u636e\u9700\u8981\u91cd\u590d\u601d\u60f3\u548c\u884c\u52a8\u5faa\u73af\u3002<\/li>\n<li>\u5f53\u5b83\u6709\u8db3\u591f\u7684\u4fe1\u606f\u65f6\uff0c\u5b83\u8fdb\u5165answer\u72b6\u6001\u3002<\/li>\n<li>\u6839\u636e\u6536\u96c6\u5230\u7684\u6240\u6709\u4fe1\u606f\u751f\u6210\u6700\u7ec8\u54cd\u5e94\u3002<\/li>\n<li>\u53ea\u8981\u7ef4\u57fa\u767e\u79d1\u6ca1\u6709\u53ef\u6536\u96c6\u7684\u6570\u636e\uff0c\u5c31\u8fdb\u5165\u65e0\u9650\u5faa\u73af\u3002\u7528\u8ba1\u65f6\u5668\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898=p<\/li>\n<\/ol>\n<h2> [7] \u6700\u540e\u7684\u8003\u8651 <\/h2>\n<ul>\n<li>\u6a21\u5757\u5316\u7ed3\u6784\u53ef\u4ee5\u8f7b\u677e\u6dfb\u52a0\u65b0\u5de5\u5177\u6216 api\u3002<\/li>\n<li>\u5b9e\u65bd\u9519\u8bef\u5904\u7406\u548c\u65f6\u95f4\/\u8fed\u4ee3\u9650\u5236\u975e\u5e38\u91cd\u8981\uff0c\u4ee5\u907f\u514d\u65e0\u9650\u5faa\u73af\u6216\u8fc7\u5ea6\u7684\u8d44\u6e90\u4f7f\u7528\u3002<\/li>\n<li>\u6b64\u793a\u4f8b\u4f7f\u7528\u6e29\u5ea6 2\u3002\u6e29\u5ea6\u8d8a\u4f4e\uff0c\u4ee3\u7406\u5728\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\u7684\u521b\u9020\u529b\u5c31\u8d8a\u4f4e\u3002\u901a\u8fc7\u5b9e\u9a8c\u4e86\u89e3\u6e29\u5ea6\u5bf9 llm \u7684\u5f71\u54cd\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   iOS \u524d\u7aef\u9875\u9762\u6587\u672c\u7701\u7565\u6ea2\u51fa\u5982\u4f55\u89e3\u51b3\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en \u6536\u85cf \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300a\u4f7f\u7528 Nodejs \u521b\u5efa ReAct AI \u4ee3\u7406\uff08\u7ef4\u57fa\u767e\u79d1\u641c\u7d22\uff09en\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u4ecb\u7ecd \u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u80fd\u591f\u641c\u7d22\u7ef4\u57fa\u767e\u79d1\u5e76\u6839\u636e\u6536\u96c6\u5230\u7684\u4fe1\u606f\u56de\u7b54\u95ee\u9898\u7684\u4eba\u5de5\u667a\u80fd\u4ee3\u7406\u3002 \u8be5 react\uff08\u63a8\u7406\u548c\u884c\u52a8\uff09\u4ee3\u7406\u4f7f\u7528 google generative ai api \u6765\u5904\u7406\u67e5\u8be2\u5e76\u751f\u6210\u54cd\u5e94\u3002 \u6211\u4eec\u7684\u4ee3\u7406\u5c06\u80fd\u591f\uff1a \u5728\u7ef4\u57fa\u767e\u79d1\u4e0a\u641c\u7d22\u76f8\u5173\u4fe1\u606f\u3002 \u4ece\u7ef4\u57fa\u767e\u79d1\u9875\u9762\u4e2d\u63d0\u53d6\u7279\u5b9a\u90e8\u5206\u3002 \u5bf9\u6536\u96c6\u5230\u7684\u4fe1\u606f\u8fdb\u884c\u5206\u6790\u5e76\u5236\u5b9a\u56de\u590d\u3002 [2] \u4ec0\u4e48\u662freact\u4ee3\u7406\uff1f react agent \u662f\u4e00\u79cd\u9075\u5faa\u53cd\u5c04-\u64cd\u4f5c\u5faa\u73af\u7684\u7279\u5b9a\u7c7b\u578b\u7684\u4ee3\u7406\u3002\u5b83\u6839\u636e\u53ef\u7528\u4fe1\u606f\u548c\u53ef\u4ee5\u91c7\u53d6\u7684\u64cd\u4f5c\u6765\u53cd\u6620\u5f53\u524d\u4efb\u52a1\uff0c\u7136\u540e\u51b3\u5b9a\u91c7\u53d6\u4ec0\u4e48\u64cd\u4f5c\u6216\u662f\u5426\u5b8c\u6210\u4efb\u52a1\u3002 [3] \u89c4\u5212\u4ee3\u7406 3.1 \u6240\u9700\u5de5\u5177 node.js \u7528\u4e8e http \u8bf7\u6c42\u7684 axios \u5e93 google \u751f\u6210\u5f0f ai api (gemini-1.5-flash) \u7ef4\u57fa\u767e\u79d1 api 3.2 \u4ee3\u7406\u7ed3\u6784 \u6211\u4eec\u7684 react agent \u5c06\u5177\u6709\u4e09\u4e2a\u4e3b\u8981\u72b6\u6001\uff1a \u601d\u60f3\uff08\u53cd\u601d\uff09 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53064","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53064"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53064\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}