8
n8n 中文网amn8n.com

我的字典_复杂

高级

这是一个Personal Productivity, Multimodal AI领域的自动化工作流,包含 22 个节点。主要使用 If, Set, Code, Webhook, Supabase 等节点。 使用GPT-4o-mini和Supabase创建文学英德中词典

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • Supabase URL 和 API Key
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "6tW6bM6XI6pqrQgn",
  "meta": {
    "instanceId": "91e9d2c12dbfcdc2cb30d3665a714f8a4ee901c9fd6527015006b21570a93b53",
    "templateCredsSetupCompleted": true
  },
  "name": "我的字典_复杂",
  "tags": [],
  "nodes": [
    {
      "id": "87575fd4-3eda-4e20-8d6b-82a1ec37f1d5",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -600,
        -360
      ],
      "parameters": {
        "text": "={{ $json.body.word }}",
        "options": {
          "systemMessage": "Purpose:\nYou are a bilingual dictionary assistant that helps users understand English and German words in the context of literature. It provides Chinese definitions and three literary-style sentence examples for each word, helping users deepen their vocabulary and reading comprehension.\n\nBehavior Guidelines:\n\nInput Handling:\n\nAccept single words in either English or German.\n\nDetect the language automatically.\n\nIf ambiguous, ask the user to clarify.\n\nResponse Format:\n\nLanguage: State the input language.\n\nWord: Bold the input word.\n\nPart of Speech: Indicate (e.g., noun, verb, adjective, etc.).\n\nChinese Meaning: Provide a concise and literary-relevant translation in Simplified Chinese.\n\nExamples:\n\nProvide three example sentences.\n\nThe sentences should be literary in tone or style (poetic, novelistic, expressive).\n\nProvide translations of the examples in Simplified Chinese beneath each.\n\nFocus on Literary Use:\n\nPrioritize literary, archaic, or metaphorical meanings when available.\n\nIf a word has multiple meanings, emphasize the one most relevant to literature.\n\nTone:\n\nKeep responses clear, elegant, and not overly academic.\n\nIf a word has rich etymology or symbolism, briefly mention it.\n\n🧪 Example Interaction\nUser Input: serenity\n\nYour Response:\n\nLanguage: English\nWord: serenity\nPart of Speech: Noun\nChinese Meaning: 宁静;安详;心灵的平和(常用于描写自然或人物的内心状态)\n\nExamples:\n\nThe serenity of the moonlit lake whispered secrets to the wind.\n月光湖面的宁静向微风低语着秘密。\n\nShe wore her serenity like a veil, untouched by the chaos around her.\n她带着一种宁静的气质,如面纱般将纷乱隔绝在外。\n\nIn the quiet of dawn, serenity settled over the forest like a benediction.\n黎明的静谧中,宁静如祝福般洒落在森林之上。"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "4547dfac-fb63-4950-8413-c93d4560f05e",
      "name": "Supabase",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -360,
        420
      ],
      "parameters": {
        "tableId": "Dict",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "Words",
              "fieldValue": "={{ $json.body.word }}"
            },
            {
              "fieldId": "chineseMeaning",
              "fieldValue": "={{ $json.body.chineseMeaning }}"
            },
            {
              "fieldId": "Examples",
              "fieldValue": "={{ $json.body.examples }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "id": "ot0Q4Due2nUmSxKx",
          "name": "Supabase account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e21676fe-0d24-4b15-8121-f6b0285cc5f4",
      "name": "条件判断",
      "type": "n8n-nodes-base.if",
      "position": [
        -140,
        -360
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "71dec079-93c3-44c1-a798-a2c9df48cff5",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $('AI Agent').first().json.output }}",
              "rightValue": "It seems "
            },
            {
              "id": "52f131e5-69c7-4862-864f-76f336cf46a4",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $('AI Agent').first().json.output }}",
              "rightValue": "unclear"
            },
            {
              "id": "bc103838-6de4-4f72-bd67-03ea710c607f",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $('AI Agent').first().json.output }}",
              "rightValue": "please provide"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "eb58c75b-d4f3-4597-8b93-cd769a7e880d",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2240,
        -660
      ],
      "parameters": {
        "width": 540,
        "height": 1120,
        "content": "# 文学词典助手"
      },
      "typeVersion": 1
    },
    {
      "id": "7300514a-b5ea-40d0-8a29-02a1586cd124",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1140,
        -600
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "a8b8f6f8-9dd3-465c-8a30-66132144e2e3",
      "name": "OpenAI 翻译并提供例句",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -580,
        -180
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "sOk8ZfXyjEGfWIno",
          "name": "OpenAi account "
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3b794b96-5195-4771-bb5f-ea0ea99762a2",
      "name": "响应用户",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        820,
        -500
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "6c4ce691-a8c5-4ff4-8cd5-1103af2d34ad",
      "name": "响应用户1",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        820,
        -300
      ],
      "parameters": {
        "options": {},
        "respondWith": "text",
        "responseBody": "={{ JSON.stringify($('Format response').first().json) }}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "2e551b35-2292-4f47-ab5d-d1e658d18adc",
      "name": "格式化错误消息",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        -500
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"error\": true,\n  \"message\": \"Please provide a specific word in English or German. The input was not recognized as a valid word.\",\n  \"word\": \"{{ $('Webhook').first().json.body.word }}\"\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "69ca7f02-6991-4ef9-bc1e-f900507838ab",
      "name": "格式化响应",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        -300
      ],
      "parameters": {
        "jsCode": "// Get the AI response from the previous node\nconst aiResponse = $('AI Agent').first().json.output;\n\n// Split the response into lines for parsing\nconst lines = aiResponse.split('\\n').filter(line => line.trim() !== '');\n\nlet word = '';\nlet chineseMeaning = '';\nlet examples = [];\n\n// Parse each line to extract the needed information\nlet inExamples = false;\nlet currentExample = '';\nlet currentTranslation = '';\n\nfor (let i = 0; i < lines.length; i++) {\n  const trimmedLine = lines[i].trim();\n  \n  // Extract the word (looking for \"Word: **word**\" format)\n  if (trimmedLine.startsWith('Word:')) {\n    // Remove \"Word:\" and extract text between ** markers\n    word = trimmedLine.replace('Word:', '').trim();\n    // Remove bold markdown formatting if present\n    word = word.replace(/\\*\\*/g, '').trim();\n  }\n  \n  // Extract Chinese meaning\n  if (trimmedLine.startsWith('Chinese Meaning:')) {\n    chineseMeaning = trimmedLine.replace('Chinese Meaning:', '').trim();\n  }\n  \n  // Check if we've reached the Examples section\n  if (trimmedLine === 'Examples:' || trimmedLine.startsWith('Examples:')) {\n    inExamples = true;\n    continue;\n  }\n  \n  // Parse examples when we're in the examples section\n  if (inExamples && trimmedLine) {\n    // Check if this line is an English sentence (not a Chinese translation)\n    // Chinese translations typically start with Chinese characters\n    const isChineseTranslation = /^[\\u4e00-\\u9fff]/.test(trimmedLine);\n    \n    if (!isChineseTranslation && trimmedLine.length > 10) {\n      // This is likely an English example sentence\n      // Save the previous example if we have both parts\n      if (currentExample && currentTranslation) {\n        examples.push({\n          sentence: currentExample,\n          translation: currentTranslation\n        });\n      }\n      \n      // Start a new example\n      currentExample = trimmedLine;\n      currentTranslation = '';\n    } else if (isChineseTranslation && currentExample) {\n      // This is the Chinese translation for the current example\n      currentTranslation = trimmedLine;\n    }\n  }\n}\n\n// Don't forget to add the last example if it exists\nif (currentExample && currentTranslation) {\n  examples.push({\n    sentence: currentExample,\n    translation: currentTranslation\n  });\n}\n\n// Return the structured data\nreturn {\n  word: word,\n  chineseMeaning: chineseMeaning,\n  examples: examples\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "6c366b3a-fb16-468a-8615-a86c58398378",
      "name": "用于获取用户单词输入的 Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -940,
        -360
      ],
      "webhookId": "e50639d5-af5b-4523-864a-cb123250887f",
      "parameters": {
        "path": "e50639d5-af5b-4523-864a-cb123250887f",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "47059065-9d8c-40a0-8728-84e7030bab73",
      "name": "用于将单词保存到 Supabase 的 Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -940,
        420
      ],
      "webhookId": "e50639d5-af5b-4523-864a-cb123250887f",
      "parameters": {
        "path": "e50639d5-af5b-4523-864a-cb123250887f",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "6c098436-bbee-416d-9838-b57bb6bf71b7",
      "name": "响应消息",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        120,
        420
      ],
      "parameters": {
        "options": {},
        "respondWith": "text",
        "responseBody": "={\n  \"success\": true,\n  \"message\": \"Word saved successfully\"\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "92eff8ea-f97e-44dc-b902-f384d89ebe92",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -680,
        -20
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "62945248-fb2d-4a4c-8479-6f7f3d6b1d75",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "9b3eb8d6-9210-466e-885f-3015c1c97854",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -300,
        -640
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "8a7c23e1-d537-491d-b4c8-e7b933e3709d",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1620,
        420
      ],
      "parameters": {
        "color": 3,
        "width": 440,
        "height": 100,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "55d3c004-cb9a-41cc-884e-829785a8ffe4",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1620,
        -360
      ],
      "parameters": {
        "color": 3,
        "width": 440,
        "height": 100,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "07bc4443-1d63-4c29-8cbd-386522c73ed2",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -520,
        620
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "75a5c8ec-f15c-48dd-b140-2eaee66cd85b",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        400
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "a05d401b-792f-437d-bdd1-f08285e5ee9f",
      "name": "便签9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        620
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 220,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "27e60f98-b4ea-4b29-a2d2-c53b6b786d96",
      "name": "便签 10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1060,
        -500
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 320,
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "03878a15-0672-4cd3-baf8-40b47c357052",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Format error message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase": {
      "main": [
        [
          {
            "node": "Respond message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format response": {
      "main": [
        [
          {
            "node": "Respond to user1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond to user1": {
      "main": [
        []
      ]
    },
    "Format error message": {
      "main": [
        [
          {
            "node": "Respond to user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Openai translate & give examples": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Webhook to fetch user word input": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook to save words in Supabase": {
      "main": [
        [
          {
            "node": "Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 个人效率, 多模态 AI

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流