评估指标示例:字符串相似度

中级

这是一个Engineering、AI领域的自动化工作流,包含 12 个节点。主要使用 Set、Code、Webhook、Evaluation、HttpRequest 等节点,结合人工智能技术实现智能自动化。 评估指标示例:字符串相似度

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "bf40384a063e00f3b983f4f9bada22b57a8231a04c0fb48d363e26d7b0f2b7e7",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "b2a1a367-119f-4e2d-a982-ff675debf658",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        220,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 180,
        "height": 260,
        "content": "检查实际代码与预期代码的差异程度(得分为1表示完全匹配)"
      },
      "typeVersion": 1
    },
    {
      "id": "f5413855-20de-4b77-ba90-18610a9d9b4d",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1300,
        40
      ],
      "parameters": {
        "width": 300,
        "height": 500,
        "content": "## 工作原理"
      },
      "typeVersion": 1
    },
    {
      "id": "8921a4c4-cee1-44e7-8dce-55219db519d7",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -960,
        280
      ],
      "parameters": {
        "color": 7,
        "width": 220,
        "height": 220,
        "content": "读取[此测试数据集](https://docs.google.com/spreadsheets/d/1uuPS5cHtSNZ6HNLOi75A2m8nVWZrdBZ_Ivf58osDAS8/edit?gid=1786963566#gid=1786963566)的图像"
      },
      "typeVersion": 1
    },
    {
      "id": "fbf8337b-eb46-443a-8507-58a14b817be0",
      "name": "匹配 Webhook 格式",
      "type": "n8n-nodes-base.set",
      "position": [
        -680,
        340
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "=  {\n    \"headers\": {\n    },\n    \"params\": {},\n    \"query\": {\n      \"url\": {{ $json.file_url.toJsonString() }}\n    },\n    \"body\": {},\n    \"executionMode\": \"test\"\n  }"
      },
      "typeVersion": 3.4
    },
    {
      "id": "a03c9b79-d45d-4842-9325-df1af37697eb",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -900,
        40
      ],
      "webhookId": "7ceb775c-b961-44f0-acfe-682a67612332",
      "parameters": {
        "path": "7ceb775c-b961-44f0-acfe-682a67612332",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "85bd63e2-3039-4f0e-8721-bc2b843461c9",
      "name": "当获取数据集行时",
      "type": "n8n-nodes-base.evaluationTrigger",
      "position": [
        -900,
        340
      ],
      "parameters": {
        "sheetName": {
          "__rl": true,
          "mode": "url",
          "value": "https://docs.google.com/spreadsheets/d/1uuPS5cHtSNZ6HNLOi75A2m8nVWZrdBZ_Ivf58osDAS8/edit?gid=1786963566#gid=1786963566"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "https://docs.google.com/spreadsheets/d/1uuPS5cHtSNZ6HNLOi75A2m8nVWZrdBZ_Ivf58osDAS8/edit?gid=1786963566#gid=1786963566"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "bpr2LoSELMlxpwnN",
          "name": "Google Sheets account David"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "4ed0b460-70af-4f1d-a7f3-97293f9b4ce0",
      "name": "响应 Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        260,
        320
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "f1642aa1-94c5-4002-a7aa-533566dd20eb",
      "name": "正在评估?",
      "type": "n8n-nodes-base.evaluation",
      "position": [
        -20,
        200
      ],
      "parameters": {
        "operation": "checkIfEvaluating"
      },
      "typeVersion": 4.6
    },
    {
      "id": "15115588-b9ca-4e24-b7d8-f0aa0974b5dd",
      "name": "设置指标",
      "type": "n8n-nodes-base.evaluation",
      "position": [
        480,
        80
      ],
      "parameters": {
        "metrics": {
          "assignments": [
            {
              "id": "0e507b06-e6d5-4ace-aa22-f06c6db5b883",
              "name": "score",
              "type": "number",
              "value": "={{ $json.score }}"
            }
          ]
        },
        "operation": "setMetrics"
      },
      "typeVersion": 4.6
    },
    {
      "id": "af028132-c866-487d-be85-e3af049bc793",
      "name": "从图像中提取代码",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -240,
        200
      ],
      "parameters": {
        "text": "=Extract ONLY the handwritten code in the top-right corner of this image.\n\nThe code MUST follow this EXACT format:\nBT/ED/[1-3 capital letters]/[1-3 capital letters]/[1-3 capital letters]/[1-3 capital letters or empty]/[single letter + number (2-4 chars total)]\n\nExamples of correct format:\nBT/ED/ABC/DE/F/G/H1\nBT/ED/A/BC/DEF/GH/I23\nBT/ED/AB/CD/EF/GH/I234\n\nDO NOT include any explanations, notes, or other text.\nDO NOT return anything if the code doesn't match the required format.\nVERIFY the extracted code matches the format before returning it.\nReturn ONLY the extracted code - nothing else.",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "id": "Ag9qPAsY7lpIGkvC",
          "name": "JPs n8n openAI key"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "50a26635-078f-40a7-8944-2e43ed8cd482",
      "name": "计算字符串距离",
      "type": "n8n-nodes-base.code",
      "position": [
        260,
        80
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const expected_code = $('When fetching a dataset row').item.json.expected_output\nconst actual_code = $json.content\n\nfunction levenshteinDistance(str1, str2) {\n  const m = str1.length;\n  const n = str2.length;\n  const dp = Array(m + 1).fill().map(() => Array(n + 1).fill(0));\n\n  for (let i = 0; i <= m; i++) {\n    dp[i][0] = i;\n  }\n  \n  for (let j = 0; j <= n; j++) {\n    dp[0][j] = j;\n  }\n\n  for (let i = 1; i <= m; i++) {\n    for (let j = 1; j <= n; j++) {\n      if (str1[i - 1] === str2[j - 1]) {\n        dp[i][j] = dp[i - 1][j - 1];\n      } else {\n        dp[i][j] = 1 + Math.min(\n          dp[i - 1][j],     // deletion\n          dp[i][j - 1],     // insertion\n          dp[i - 1][j - 1]  // substitution\n        );\n      }\n    }\n  }\n\n  return dp[m][n];\n}\n\nconst dist = levenshteinDistance(\n  expected_code, \n  actual_code\n)\n\nconst max_dist = Math.max(\n  expected_code.length,\n  actual_code.length\n)\n\nconsole.log('truth', expected_code)\nconsole.log('effort', actual_code)\nconsole.log('dist', dist)\nconsole.log('max_dist', max_dist)\n\n$input.item.json.score = 1 - (dist / max_dist)\n\nreturn $input.item;"
      },
      "typeVersion": 2
    },
    {
      "id": "383db4b0-9665-4608-bbf9-3dca88508bff",
      "name": "下载图片",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -460,
        200
      ],
      "parameters": {
        "url": "={{ $json.query.url }}",
        "options": {}
      },
      "typeVersion": 4.2
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Download image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluating?": {
      "main": [
        [
          {
            "node": "Calc string distance",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download image": {
      "main": [
        [
          {
            "node": "Extract code from image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calc string distance": {
      "main": [
        [
          {
            "node": "Set metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match webhook format": {
      "main": [
        [
          {
            "node": "Download image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract code from image": {
      "main": [
        [
          {
            "node": "Evaluating?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When fetching a dataset row": {
      "main": [
        [
          {
            "node": "Match webhook format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

这是一个中级难度的工作流,适用于Engineering、AI等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

需要付费吗?

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

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

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

外部链接
在 n8n.io 上查看 →

分享此工作流