8
n8n 中文网amn8n.com

基于查询复杂度的 Gemini 与 GPT 模型间智能聊天路由

中级

这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 11 个节点。主要使用 Agent, ChatTrigger, LmChatOpenAi, ModelSelector, LmChatGoogleGemini 等节点。 基于查询复杂度的 Gemini 与 GPT 模型间智能聊天路由

前置要求
  • OpenAI API Key
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "3d7eb9567ae690bf8c9bba1cb43396e6e40c18e15eb5889cf9673ed1713da6db",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "77530f0b-8f16-4427-a45c-54c82c66588a",
      "name": "模型选择器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1184,
        1904
      ],
      "parameters": {
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "=# Overview\nYou are an AI agent responsible for selecting the most suitable large language model to handle a given user request. Determine whether the question is simple or complex.\n\n## Instructions\nAnalyze the user's request and return only a single number based on the complexity of the task.\n\n## Classification Rules\n- **Output 1**: Complex questions requiring deep reasoning, professional writing, research, coding, or multi-step problem solving\n- **Output 2**: Simple questions that are straightforward, conversational, or can be answered quickly\n\n## Output Format\nReturn only one of the following:\n- 1\n- 2\n\nNo explanations, no newline or spaces, no formatting, no extra text. Only the number."
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "9fe14e1d-1f15-4095-b338-c96ef00a9b47",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        976,
        1904
      ],
      "webhookId": "2c54aa53-9406-4d0c-9217-d78b8f9cb137",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "530ca74e-ff27-4400-8527-57e9d62e3a61",
      "name": "模型选择器",
      "type": "@n8n/n8n-nodes-langchain.modelSelector",
      "position": [
        1440,
        2096
      ],
      "parameters": {
        "rules": {
          "rule": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f7148b18-d2be-4618-a12c-6f144f1eab14",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Model Selector').item.json.output.toNumber() }}",
                    "rightValue": 1
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c30c1080-35d3-4cf0-a871-8034049d9d10",
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Model Selector').item.json.output.toNumber() }}",
                    "rightValue": 2
                  }
                ]
              }
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ba211db9-bf65-4f71-9755-a47ebfea1b86",
      "name": "主代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1520,
        1904
      ],
      "parameters": {
        "text": "={{ $('When chat message received').item.json.chatInput }}",
        "options": {
          "systemMessage": "=Here is the current date/time: {{ $now }}"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "6afd02b9-9a79-40fc-a26c-e73b837d3eda",
      "name": "4.1 nano",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1488,
        2352
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "=gpt-4.1-nano"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "ymMvgDroJHalwvRf",
          "name": "OpenAI"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "83ca2ffd-aff1-482b-b87b-052e9f9cc193",
      "name": "2.5 pro",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1440,
        2240
      ],
      "parameters": {
        "options": {},
        "modelName": "=models/gemini-2.5-pro"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "7v8o9EaQkl33woxm",
          "name": "v9"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9f603eb2-6ef2-43ef-8519-759eca7e91df",
      "name": "2.0 flash",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1184,
        2112
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "8XtobpsLkdYQTldy",
          "name": "Gemini v6"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c60c1f49-3732-4307-9538-86fd8b93a58c",
      "name": "概述说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        1776
      ],
      "parameters": {
        "color": 4,
        "width": 600,
        "height": 1000,
        "content": "# 自适应 LLM 路由器用于优化 AI 聊天响应"
      },
      "typeVersion": 1
    },
    {
      "id": "00acaca1-2394-4609-bfc0-409c1f281194",
      "name": "说明:触发器",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        928,
        2096
      ],
      "parameters": {
        "width": 252,
        "height": 192,
        "content": "## 📥 当收到聊天消息时"
      },
      "typeVersion": 1
    },
    {
      "id": "fb5bad8f-6436-4a67-b0d5-fe7c2a3a58df",
      "name": "说明:分类器",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1152,
        1712
      ],
      "parameters": {
        "color": 2,
        "width": 332,
        "content": "## 🤖模型选择器"
      },
      "typeVersion": 1
    },
    {
      "id": "f91cfe72-69c0-4627-b508-0159497317ca",
      "name": "说明:主代理",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        2048
      ],
      "parameters": {
        "color": 5,
        "width": 284,
        "height": 192,
        "content": "## 💬 节点:主代理"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "2.5 pro": {
      "ai_languageModel": [
        [
          {
            "node": "Model selector",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "4.1 nano": {
      "ai_languageModel": [
        [
          {
            "node": "Model selector",
            "type": "ai_languageModel",
            "index": 1
          }
        ]
      ]
    },
    "2.0 flash": {
      "ai_languageModel": [
        [
          {
            "node": "Model Selector",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Model Selector": {
      "main": [
        [
          {
            "node": "Main Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Model selector": {
      "ai_languageModel": [
        [
          {
            "node": "Main Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Model Selector",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 内容创作, 多模态 AI

需要付费吗?

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

工作流信息
难度等级
中级
节点数量11
分类2
节点类型6
难度说明

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

作者

AI Automation Consultant | Helping Business Owners Implement AI Systems for growth and lead gen

外部链接
在 n8n.io 查看

分享此工作流