-
-
Save dangehub/08da7d942d702153ed3b2f6854fbeba9 to your computer and use it in GitHub Desktop.
n8n-反思翻译法-包装为划词翻译api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "三步翻译法(参考FastGPT)- 多语言划词翻译api", | |
"nodes": [ | |
{ | |
"parameters": { | |
"model": "deepseek-chat", | |
"options": { | |
"baseURL": "https://api.deepseek.com/v1" | |
} | |
}, | |
"id": "8f39d21b-819a-4888-9f05-9399ab040131", | |
"name": "OpenAI Chat Model", | |
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", | |
"typeVersion": 1, | |
"position": [ | |
1320, | |
460 | |
], | |
"credentials": { | |
"openAiApi": { | |
"id": "9m5WfL5BwIKiglU5", | |
"name": "deepseek" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"respondWith": "json", | |
"responseBody": "={\n \"text\": \"翻译内容\", \n \"from\": \"{{ $('Webhook').item.json[\"body\"][\"destination\"][1] }}\", \n \"to\": \"{{ $('Webhook').item.json[\"body\"][\"destination\"][0] }}\", \n \"result\": [\"{{ $json[\"content\"] }}\"]\n}", | |
"options": {} | |
}, | |
"id": "da7ec029-c054-4af6-8d4f-25cc42a005c1", | |
"name": "Respond to Webhook", | |
"type": "n8n-nodes-base.respondToWebhook", | |
"typeVersion": 1.1, | |
"position": [ | |
2000, | |
180 | |
] | |
}, | |
{ | |
"parameters": { | |
"assignments": { | |
"assignments": [ | |
{ | |
"id": "2b42ed42-e965-4fd1-bb4b-3dd1a3d489eb", | |
"name": "content", | |
"value": "={{ $json.output.replace(/(?:\\\"|(?:\\r\\n|\\\\r|\\\\n|\\n))/g, '')}}", | |
"type": "string" | |
} | |
] | |
}, | |
"options": {} | |
}, | |
"id": "52b4d6db-8580-4845-92ce-334086620899", | |
"name": "去除换行符", | |
"type": "n8n-nodes-base.set", | |
"typeVersion": 3.4, | |
"position": [ | |
1700, | |
160 | |
] | |
}, | |
{ | |
"parameters": { | |
"model": "deepseek-chat", | |
"options": { | |
"baseURL": "https://api.deepseek.com/v1" | |
} | |
}, | |
"id": "b51a6146-1720-416e-a54a-deb05464f63a", | |
"name": "OpenAI Chat Model1", | |
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", | |
"typeVersion": 1, | |
"position": [ | |
500, | |
800 | |
], | |
"credentials": { | |
"openAiApi": { | |
"id": "9m5WfL5BwIKiglU5", | |
"name": "deepseek" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"jsCode": "const inputData = $input.all();\nconst textToTruncate = items[0].json.body.text; // 假设传入的变量名为textToTruncate\n\nif (textToTruncate && typeof textToTruncate === 'string') {\n const truncatedText = textToTruncate.slice(0, 30);\n \n return {\n truncatedText: truncatedText\n };\n} else {\n return {\n error: '输入无效或不是字符串'\n };\n}" | |
}, | |
"id": "78ddccce-3720-4e05-a041-e3baddebc7e4", | |
"name": "截取50字分析源语言", | |
"type": "n8n-nodes-base.code", | |
"typeVersion": 2, | |
"position": [ | |
220, | |
460 | |
] | |
}, | |
{ | |
"parameters": { | |
"assignments": { | |
"assignments": [ | |
{ | |
"id": "a32ca810-1388-4dd2-b6ad-1f449a174833", | |
"name": "body.text", | |
"value": "={{ $json.body.text }}", | |
"type": "string" | |
} | |
] | |
}, | |
"options": {} | |
}, | |
"id": "27df2250-dcda-453a-b8e5-42f0612d9e61", | |
"name": "Edit Fields", | |
"type": "n8n-nodes-base.set", | |
"typeVersion": 3.4, | |
"position": [ | |
220, | |
760 | |
] | |
}, | |
{ | |
"parameters": { | |
"conditions": { | |
"options": { | |
"caseSensitive": true, | |
"leftValue": "", | |
"typeValidation": "strict" | |
}, | |
"conditions": [ | |
{ | |
"id": "e7f2b381-ff8e-454b-bbb2-db0f22853603", | |
"leftValue": "={{ $('Webhook').item.json.body.destination[0] }}", | |
"rightValue": "={{ $json.text }}", | |
"operator": { | |
"type": "string", | |
"operation": "equals", | |
"name": "filter.operator.equals" | |
} | |
} | |
], | |
"combinator": "and" | |
}, | |
"options": {} | |
}, | |
"id": "f5d951a7-f363-4806-830f-070013b3423d", | |
"name": "If", | |
"type": "n8n-nodes-base.if", | |
"typeVersion": 2, | |
"position": [ | |
820, | |
440 | |
] | |
}, | |
{ | |
"parameters": { | |
"agent": "conversationalAgent", | |
"promptType": "define", | |
"text": "=请你把下文从翻译从{{ $json.text }}翻译为{{ $('Webhook').item.json.body.destination[1] }},\n\n<待翻译内容>\n{{ $('Webhook').item.json.body.text }}\n<待翻译内容/> ", | |
"options": { | |
"systemMessage": "# Role: 资深多语言翻译专家\n\n## Background:\n你是一位经验丰富的翻译专家,精通多语言互译,尤其擅长将一种语言译成流畅易懂的另一种语言。你曾多次带领团队完成大型翻译项目,译文广受好评。\n\n## Attention:\n- 翻译过程中要始终坚持\"信、达、雅\"的原则,但\"达\"尤为重要\n- 译文要符合目标语言的表达习惯,通俗易懂,连贯流畅 \n- 避免使用过于文绉绉的表达和晦涩难懂的典故引用\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Constraints:\n- 必须严格遵循四轮翻译流程:直译、意译、校审、定稿 \n- 译文要忠实原文,准确无误,不能遗漏或曲解原意\n- 每一轮翻译前后必须添加【思考】和【翻译】标记\n- 最终译文使用Markdown的代码块呈现\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Goals:\n- 通过四轮翻译流程,将英文原文译成高质量的译文 \n- 译文要准确传达原文意思,语言表达力求浅显易懂,朗朗上口\n- 适度使用一些熟语俗语、流行网络用语等,增强译文的亲和力\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Skills:\n- 精通多种语言,具有扎实的语言功底和丰富的翻译经验\n- 擅长将原语言表达习惯转换为地道自然的目标语言\n- 对当代各种语言的发展变化有敏锐洞察,善于把握语言流行趋势\n\n## Workflow:\n1. 第一轮直译:逐字逐句忠实原文,不遗漏任何信息\n2. 第二轮意译:在直译的基础上用通俗流畅的目标语言意译原文,至少提供2个不同风格的版本\n3. 第三轮校审:仔细审视译文,消除偏差和欠缺,使译文更加地道易懂 \n4. 第四轮定稿:择优选取,反复修改润色,最终定稿出一个简洁畅达、符合大众阅读习惯的译文\n\n## OutputFormat: \n- 每一轮翻译前用【思考】说明该轮要点\n- 每一轮翻译后用【翻译】呈现译文\n- 直接输出最终定稿译文,不要增加任何多余的东西\n\n## Suggestions:\n- 直译时力求忠实原文,但不要过于拘泥逐字逐句\n- 意译时在准确表达原意的基础上,用最朴实无华的现代汉语来表达 \n- 校审环节重点关注译文是否符合当代表达习惯,是否通俗易懂\n- 定稿时适度采用一些熟语谚语、网络流行语等,使译文更接地气\n- 善于利用语言的灵活性,用不同的表述方式展现同一内容,提高译文的可读性\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话", | |
"maxIterations": 6 | |
} | |
}, | |
"id": "fd5cb0cc-c7ab-46e9-bfbb-fc8f89be4a16", | |
"name": "AI Agent", | |
"type": "@n8n/n8n-nodes-langchain.agent", | |
"typeVersion": 1.6, | |
"position": [ | |
1300, | |
200 | |
] | |
}, | |
{ | |
"parameters": { | |
"model": "deepseek-chat", | |
"options": { | |
"baseURL": "https://api.deepseek.com/v1" | |
} | |
}, | |
"id": "446f96ae-65cc-4f86-af70-f49eabe7e498", | |
"name": "OpenAI Chat Model2", | |
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", | |
"typeVersion": 1, | |
"position": [ | |
1300, | |
960 | |
], | |
"credentials": { | |
"openAiApi": { | |
"id": "9m5WfL5BwIKiglU5", | |
"name": "deepseek" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"respondWith": "json", | |
"responseBody": "={\n \"text\": \"翻译内容\", \n \"from\": \"{{ $('Webhook').item.json[\"body\"][\"destination\"][1] }}\", \n \"to\": \"{{ $('Webhook').item.json[\"body\"][\"destination\"][0] }}\", \n \"result\": [\"{{ $json[\"content\"] }}\"]\n}", | |
"options": {} | |
}, | |
"id": "d0aa23fa-012e-41a7-a064-4be95b5dbc21", | |
"name": "Respond to Webhook1", | |
"type": "n8n-nodes-base.respondToWebhook", | |
"typeVersion": 1.1, | |
"position": [ | |
2040, | |
620 | |
] | |
}, | |
{ | |
"parameters": { | |
"assignments": { | |
"assignments": [ | |
{ | |
"id": "2b42ed42-e965-4fd1-bb4b-3dd1a3d489eb", | |
"name": "content", | |
"value": "={{ $json.output.replace(/(?:\\\"|(?:\\r\\n|\\\\r|\\\\n|\\n))/g, '')}}", | |
"type": "string" | |
} | |
] | |
}, | |
"options": {} | |
}, | |
"id": "1aced3ab-5658-4ccd-9a4c-98b5a6834e5d", | |
"name": "去除换行符1", | |
"type": "n8n-nodes-base.set", | |
"typeVersion": 3.4, | |
"position": [ | |
1720, | |
680 | |
] | |
}, | |
{ | |
"parameters": { | |
"httpMethod": "POST", | |
"path": "f373d650-8773-4fd3-916a-6e5aaa834392", | |
"responseMode": "responseNode", | |
"options": {} | |
}, | |
"id": "8844be23-5076-43c5-ae46-47011c51a825", | |
"name": "Webhook", | |
"type": "n8n-nodes-base.webhook", | |
"typeVersion": 2, | |
"position": [ | |
-60, | |
600 | |
], | |
"webhookId": "45f1fea7-17bb-4126-9c8c-f425639f44f2" | |
}, | |
{ | |
"parameters": { | |
"agent": "conversationalAgent", | |
"promptType": "define", | |
"text": "=请你把下文从翻译从{{ $json.text }}翻译为{{ $('Webhook').item.json.body.destination[0] }},\n\n<待翻译内容>\n{{ $('Webhook').item.json.body.text }}\n<待翻译内容/> ", | |
"options": { | |
"systemMessage": "# Role: 资深多语言翻译专家\n\n## Background:\n你是一位经验丰富的翻译专家,精通多语言互译,尤其擅长将一种语言译成流畅易懂的另一种语言。你曾多次带领团队完成大型翻译项目,译文广受好评。\n\n## Attention:\n- 翻译过程中要始终坚持\"信、达、雅\"的原则,但\"达\"尤为重要\n- 译文要符合目标语言的表达习惯,通俗易懂,连贯流畅 \n- 避免使用过于文绉绉的表达和晦涩难懂的典故引用\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Constraints:\n- 必须严格遵循四轮翻译流程:直译、意译、校审、定稿 \n- 译文要忠实原文,准确无误,不能遗漏或曲解原意\n- 每一轮翻译前后必须添加【思考】和【翻译】标记\n- 最终译文使用Markdown的代码块呈现\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Goals:\n- 通过四轮翻译流程,将英文原文译成高质量的译文 \n- 译文要准确传达原文意思,语言表达力求浅显易懂,朗朗上口\n- 适度使用一些熟语俗语、流行网络用语等,增强译文的亲和力\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Skills:\n- 精通多种语言,具有扎实的语言功底和丰富的翻译经验\n- 擅长将原语言表达习惯转换为地道自然的目标语言\n- 对当代各种语言的发展变化有敏锐洞察,善于把握语言流行趋势\n\n## Workflow:\n1. 第一轮直译:逐字逐句忠实原文,不遗漏任何信息\n2. 第二轮意译:在直译的基础上用通俗流畅的目标语言意译原文,至少提供2个不同风格的版本\n3. 第三轮校审:仔细审视译文,消除偏差和欠缺,使译文更加地道易懂 \n4. 第四轮定稿:择优选取,反复修改润色,最终定稿出一个简洁畅达、符合大众阅读习惯的译文\n\n## OutputFormat: \n- 每一轮翻译前用【思考】说明该轮要点\n- 每一轮翻译后用【翻译】呈现译文\n- 直接输出最终定稿译文,不要增加任何多余的东西\n\n## Suggestions:\n- 直译时力求忠实原文,但不要过于拘泥逐字逐句\n- 意译时在准确表达原意的基础上,用最朴实无华的现代汉语来表达 \n- 校审环节重点关注译文是否符合当代表达习惯,是否通俗易懂\n- 定稿时适度采用一些熟语谚语、网络流行语等,使译文更接地气\n- 善于利用语言的灵活性,用不同的表述方式展现同一内容,提高译文的可读性\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话", | |
"maxIterations": 6 | |
} | |
}, | |
"id": "dcc453e8-6963-4d9f-bcb0-e07fdeeda67c", | |
"name": "AI Agent1", | |
"type": "@n8n/n8n-nodes-langchain.agent", | |
"typeVersion": 1.6, | |
"position": [ | |
1280, | |
700 | |
] | |
}, | |
{ | |
"parameters": { | |
"promptType": "define", | |
"text": "=请你识别下文是什么语言,并从{\"中文(简体)\",\"英语\",\"日语\"}中选择一个回答,只能使用选项中的值来回答,不要加入多余的字符,不要输出引号。\n\n<待识别文字>\n{{ $json.truncatedText }}\n<待识别文字/> " | |
}, | |
"id": "430ef4d8-08be-4baa-b568-7693582453d4", | |
"name": "确定源语言", | |
"type": "@n8n/n8n-nodes-langchain.chainLlm", | |
"typeVersion": 1.4, | |
"position": [ | |
480, | |
460 | |
] | |
} | |
], | |
"pinData": {}, | |
"connections": { | |
"OpenAI Chat Model": { | |
"ai_languageModel": [ | |
[ | |
{ | |
"node": "AI Agent", | |
"type": "ai_languageModel", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"去除换行符": { | |
"main": [ | |
[ | |
{ | |
"node": "Respond to Webhook", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"OpenAI Chat Model1": { | |
"ai_languageModel": [ | |
[ | |
{ | |
"node": "确定源语言", | |
"type": "ai_languageModel", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"截取50字分析源语言": { | |
"main": [ | |
[ | |
{ | |
"node": "确定源语言", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"If": { | |
"main": [ | |
[ | |
{ | |
"node": "AI Agent", | |
"type": "main", | |
"index": 0 | |
} | |
], | |
[ | |
{ | |
"node": "AI Agent1", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"AI Agent": { | |
"main": [ | |
[ | |
{ | |
"node": "去除换行符", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"OpenAI Chat Model2": { | |
"ai_languageModel": [ | |
[ | |
{ | |
"node": "AI Agent1", | |
"type": "ai_languageModel", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"去除换行符1": { | |
"main": [ | |
[ | |
{ | |
"node": "Respond to Webhook1", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Webhook": { | |
"main": [ | |
[ | |
{ | |
"node": "截取50字分析源语言", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "Edit Fields", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"AI Agent1": { | |
"main": [ | |
[ | |
{ | |
"node": "去除换行符1", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"确定源语言": { | |
"main": [ | |
[ | |
{ | |
"node": "If", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
} | |
}, | |
"active": true, | |
"settings": { | |
"executionOrder": "v1" | |
}, | |
"versionId": "a10a9262-5477-45e4-b5e7-031793ca3b64", | |
"meta": { | |
"templateCredsSetupCompleted": true, | |
"instanceId": "de9d7d493e5fc7cb51768fabb59a09aed304e1ef860b672c88092a524e833c4e" | |
}, | |
"id": "uhr5MkuJBKPOCFzC", | |
"tags": [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment