8
n8n 中文网amn8n.com

使用OpenAI和Google表格轻松比较LLMs

高级

这是一个Engineering, AI领域的自动化工作流,包含 21 个节点。主要使用 Set, SplitOut, Aggregate, Summarize, GoogleSheets 等节点,结合人工智能技术实现智能自动化。 使用Google表格并排比较不同LLM的响应

前置要求
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移

无法加载工作流预览

导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "",
  "meta": {
    "instanceId": "",
    "templateCredsSetupCompleted": true
  },
  "name": "使用OpenAI和Google Sheets轻松比较LLMs",
  "tags": [],
  "nodes": [
    {
      "id": "",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -7400,
        3040
      ],
      "webhookId": "",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -5960,
        3040
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -4880,
        3000
      ],
      "parameters": {
        "sessionKey": "={{$('Set model, sessionId, chatInput, sessionIdBase').item.json.sessionId}}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "",
      "name": "聊天记忆管理器",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        -4980,
        3180
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -8120,
        2600
      ],
      "parameters": {
        "color": 5,
        "width": 640,
        "height": 1180,
        "content": "## 使用OpenAI和Google Sheets轻松比较LLMs"
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "OpenRouter聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -5180,
        3000
      ],
      "parameters": {
        "model": "={{$json.model}}"
      },
      "credentials": {
        "openRouterApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -7220,
        2620
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "height": 580,
        "content": "## 定义要比较的模型"
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -6500,
        2620
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "height": 580,
        "content": "## 设置模型、会话ID、聊天输入、基础会话ID"
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "设置模型、会话ID、聊天输入、基础会话ID",
      "type": "n8n-nodes-base.set",
      "position": [
        -6380,
        3040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "",
              "name": "model",
              "type": "string",
              "value": "={{ $json.models }}"
            },
            {
              "id": "",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('When chat message received').item.json.sessionId }}{{$json.models }}"
            },
            {
              "id": "",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $('When chat message received').item.json.chatInput }}"
            },
            {
              "id": "",
              "name": "sessionIdBase",
              "type": "string",
              "value": "={{ $('When chat message received').item.json.sessionId }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -5480,
        3180
      ],
      "parameters": {
        "options": {
          "returnIntermediateSteps": false
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -5600,
        3160
      ],
      "parameters": {
        "color": 7,
        "width": 540,
        "height": 520,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -5040,
        3160
      ],
      "parameters": {
        "color": 7,
        "width": 380,
        "height": 520,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4640,
        3160
      ],
      "parameters": {
        "color": 7,
        "width": 380,
        "height": 760,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "连接聊天回答",
      "type": "n8n-nodes-base.summarize",
      "position": [
        -5300,
        2620
      ],
      "parameters": {
        "options": {},
        "fieldsToSummarize": {
          "values": [
            {
              "field": "output",
              "separateBy": "\n",
              "aggregation": "concatenate"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -5080,
        2120
      ],
      "parameters": {
        "color": 5,
        "width": 460,
        "height": 500,
        "content": "## 将模型结果添加到Google Sheet"
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "为评估分组模型输出",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -5300,
        2440
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "model_answer"
            },
            {
              "fieldToAggregate": "context"
            },
            {
              "fieldToAggregate": "chatInput"
            },
            {
              "fieldToAggregate": "sessionIdBase"
            },
            {
              "fieldToAggregate": "model"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "将模型结果添加到Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "onError": "continueRegularOutput",
      "position": [
        -4940,
        2440
      ],
      "parameters": {
        "columns": {
          "value": {
            "sessionId": "={{ $json.sessionIdBase[0] }}",
            "model_1_id": "={{ $json.model[0] }}",
            "model_2_id": "={{ $json.model[1] }}",
            "user_input": "={{ $json.chatInput[0] }}",
            "model_1_answer": "={{ $json.model_answer[0] }}",
            "model_2_answer": "={{ $json.model_answer[1] }}",
            "context_model_1": "={{ $json.context[0] }}",
            "context_model_2": "={{ $json.context[1] }}"
          },
          "schema": [
            {
              "id": "sessionId",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "sessionId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "model_1_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "model_1_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "model_2_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "model_2_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "user_input",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "user_input",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "model_1_answer",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "model_1_answer",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "model_2_answer",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "model_2_answer",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "model_1_eval",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "model_1_eval",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "model_2_eval",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "model_2_eval",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "context_model_1",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "context_model_1",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "context_model_2",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "context_model_2",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1grO5jxm05kJ7if9wBIOozjkqW27i8tRedrheLRrpxf4/",
          "cachedResultName": "llms_eval"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1grO5jxm05kJ7if9wBIOozjkqW27i8tRedrheLRrpxf4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1grO5jxm05kJ7if9wBIOozjkqW27i8tRedrheLRrpxf4/",
          "cachedResultName": "Template - Easy LLMs Eval"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "",
          "name": ""
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "",
      "name": "为聊天和Google Sheets准备数据",
      "type": "n8n-nodes-base.set",
      "position": [
        -4500,
        3180
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "",
              "name": "output",
              "type": "string",
              "value": "=### `{{ $('Set model, sessionId, chatInput, sessionIdBase').item.json.model }}` answered :\n\n\n{{ $('AI Agent').item.json.output }}\n\n----------\n"
            },
            {
              "id": "",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $('Set model, sessionId, chatInput, sessionIdBase').item.json.chatInput }}"
            },
            {
              "id": "",
              "name": "model_answer",
              "type": "string",
              "value": "={{ $('AI Agent').item.json.output }}"
            },
            {
              "id": "",
              "name": "model",
              "type": "string",
              "value": "={{ $('Set model, sessionId, chatInput, sessionIdBase').item.json.model }}"
            },
            {
              "id": "",
              "name": "context",
              "type": "string",
              "value": "={{\n  (() => {\n    const history = $json[\"messages\"]; // ou adapter selon ton chemin réel\n    if (!Array.isArray(history) || history.length <= 1) {\n      return \"No prior context available — likely the user's first message or memory not yet initialized.\";\n    }\n\n    const truncated = history.slice(0, -1); // on enlève le dernier échange\n    return truncated.map(pair => `Human: ${pair.human}\\nAI: ${pair.ai}`).join('\\n');\n  })()\n}}\n"
            },
            {
              "id": "",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('Loop Over Items').item.json.sessionId }}"
            },
            {
              "id": "",
              "name": "sessionIdBase",
              "type": "string",
              "value": "={{ $('Loop Over Items').item.json.sessionIdBase }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "",
      "name": "定义要比较的模型",
      "type": "n8n-nodes-base.set",
      "position": [
        -7100,
        3040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "",
              "name": "=models",
              "type": "array",
              "value": "=[\"openai/gpt-4.1\", \"mistralai/mistral-large\"]"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "",
      "name": "将模型拆分为项目",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -6760,
        3040
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "models"
      },
      "typeVersion": 1
    },
    {
      "id": "",
      "name": "为聊天界面设置输出",
      "type": "n8n-nodes-base.set",
      "position": [
        -4940,
        2620
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "",
              "name": "output",
              "type": "string",
              "value": "={{ $json.concatenated_output }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Chat Memory Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Chat Memory Manager",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Concatenate Chat Answers",
            "type": "main",
            "index": 0
          },
          {
            "node": "Group Model Outputs for Evaluation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Memory Manager": {
      "main": [
        [
          {
            "node": "Prepare Data for Chat and Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Split Models into Items": {
      "main": [
        [
          {
            "node": "Set model, sessionId, chatInput, sessionIdBase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Concatenate Chat Answers": {
      "main": [
        [
          {
            "node": "Set Output for Chat UI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Models to Compare": {
      "main": [
        [
          {
            "node": "Split Models into Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Define Models to Compare",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group Model Outputs for Evaluation": {
      "main": [
        [
          {
            "node": "Add Model Results to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Data for Chat and Google Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set model, sessionId, chatInput, sessionIdBase": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 工程, 人工智能

需要付费吗?

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

工作流信息
难度等级
高级
节点数量21
分类2
节点类型12
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Dataki

Dataki

@dataki

I am passionate about transforming complex processes into seamless automations with n8n. My expertise spans across creating ETL pipelines, sales automations, and data & AI-driven workflows. As an avid problem solver, I thrive on optimizing workflows to drive efficiency and innovation.

外部链接
在 n8n.io 查看

分享此工作流