8
n8n 中文网amn8n.com

使用自动GPT和Gemini故障转移链构建弹性AI工作流

中级

这是一个AI领域的自动化工作流,包含 9 个节点。主要使用 Set, ManualTrigger, Code, Agent, LmChatOpenAi 等节点,结合人工智能技术实现智能自动化。 使用自动GPT和Gemini故障转移链构建弹性AI工作流

前置要求
  • OpenAI API Key
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0"
  },
  "nodes": [
    {
      "id": "180a023e-a350-4315-a7f2-968d052f634d",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        280,
        -20
      ],
      "parameters": {
        "text": "Only output \"test\".",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "32f3f1ad-8e72-427b-9bcf-0686ae3c4c5c",
      "name": "代理变量",
      "type": "n8n-nodes-base.set",
      "position": [
        -40,
        -20
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "38ce3db6-ce1d-4091-9645-39e674ad1782",
              "name": "models",
              "type": "array",
              "value": "[\"gemini-2.5-flash\"]"
            },
            {
              "id": "151da1bf-a82a-40a9-bca2-a85ab48f1c5b",
              "name": "fail_count",
              "type": "number",
              "value": "={{ $('Agent Variables')?.isExecuted ? $('Agent Variables').last()?.json?.fail_count + 1 : 0 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2d7804a4-3744-4866-89b2-705bbec66acc",
      "name": "备用模型",
      "type": "@n8n/n8n-nodes-langchain.code",
      "position": [
        280,
        500
      ],
      "parameters": {
        "code": {
          "supplyData": {
            "code": "let llms = await this.getInputConnectionData('ai_languageModel', 0);\nllms.reverse(); // reverse array, so the order matches the UI elements\n\nconst llm_index = $input.item.json.fail_count;\n\nif (!Number.isInteger(llm_index)) {\n  console.log(\"'llm_index' is udefined or not a valid integer\");\n  throw new Error(\"'llm_index' is udefined or not a valid integer\");\n}\n\nif(typeof llms[llm_index] === 'undefined') {\n  console.log(`No LLM found with index ${llm_index}`);\n  throw new Error(`No LLM found with index ${llm_index}`);\n}\n\nreturn llms[llm_index];"
          }
        },
        "inputs": {
          "input": [
            {
              "type": "ai_languageModel",
              "required": true
            }
          ]
        },
        "outputs": {
          "output": [
            {
              "type": "ai_languageModel"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e3d0d416-2571-4e86-b701-27aee1e5856e",
      "name": "首选模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        300,
        700
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "75ce0d64-dcbd-47bf-a15b-802fa979333a",
      "name": "备用模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        420,
        700
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemma-3-27b-it"
      },
      "typeVersion": 1
    },
    {
      "id": "10efe391-496f-45db-ae13-52324b41b4ff",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        200
      ],
      "parameters": {
        "color": 6,
        "width": 420,
        "height": 640,
        "content": "### ⚙️ 在此配置您的备用链 ⚙️"
      },
      "typeVersion": 1
    },
    {
      "id": "93797015-159e-4e43-bf72-47f0533e92f1",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 340,
        "height": 320,
        "content": "#### 📝 在此定义您的提示词"
      },
      "typeVersion": 1
    },
    {
      "id": "4cedd679-70d3-41a2-9bf5-addf8e146c9a",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 320,
        "content": "#### 🔁 循环控制器"
      },
      "typeVersion": 1
    },
    {
      "id": "4b5e9318-16fd-4e69-add6-0edbca278d91",
      "name": "手动触发器",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -320,
        -20
      ],
      "parameters": {},
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "AI Agent": {
      "main": [
        [],
        [
          {
            "node": "Agent Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "First Model": {
      "ai_languageModel": [
        [
          {
            "node": "Fallback Models",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Falback Model": {
      "ai_languageModel": [
        [
          {
            "node": "Fallback Models",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Agent Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent Variables": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fallback Models": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 人工智能

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量9
分类1
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Lucas Peyrin

Lucas Peyrin

@lucaspeyrin

Innovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline.

外部链接
在 n8n.io 查看

分享此工作流