Skip to content

调用 API 获取数据#

¥Call an API to fetch data

使用 n8n 将任何 API 中的数据导入你的 AI。此工作流使用 聊天触发器 提供聊天界面,并使用 调用 n8n 工作流工具 调用第二个工作流来调用 API。第二个工作流使用 AI 功能,根据用户的查询优化 API 请求。

¥Use n8n to bring data from any API to your AI. This workflow uses the Chat Trigger to provide the chat interface, and the Call n8n Workflow Tool to call a second workflow that calls the API. The second workflow uses AI functionality to refine the API request based on the user's query.

Workflow preview placeholder.

主要功能#

¥Key features

此工作流程使用:

¥This workflow uses:

  • 聊天触发器:启动你的工作流并响应用户聊天互动。该节点提供可自定义的聊天界面。

¥Chat Trigger: start your workflow and respond to user chat interactions. The node provides a customizable chat interface.

  • 代理:AI 工作流的关键部分。代理与工作流的其他组件交互,并决定使用哪些工具。

¥Agent: the key piece of the AI workflow. The Agent interacts with other components of the workflow and makes decisions about what tools to use.

  • 调用 n8n 工作流工具:将 n8n 工作流作为自定义工具插入。在 AI 中,工具是 AI 可以用来与外部世界(在本例中,指你的工作流提供的数据)交互的界面。人工智能模型使用该工具访问其内置数据集之外的信息。

¥Call n8n Workflow Tool: plug in n8n workflows as custom tools. In AI, a tool is an interface the AI can use to interact with the world (in this case, the data provided by your workflow). The AI model uses the tool to access information beyond its built-in dataset.

¥A Basic LLM Chain with an Auto-fixing Output Parser and Structured Output Parser to read the user's query and set parameters for the API call based on the user input.

使用示例#

¥Using the example

To load the template into your n8n instance:

  1. Download the workflow JSON file.
  2. Open a new workflow in your n8n instance.
  3. Copy in the JSON, or select Workflow menu Workflow menu icon > Import from file....

The example workflows use Sticky Notes to guide you:

  • Yellow: notes and information.
  • Green: instructions to run the workflow.
  • Orange: you need to change something to make the workflow work.
  • Blue: draws attention to a key feature of the example.