Skip to content

Instantly share code, notes, and snippets.

@dangehub
Created February 6, 2025 14:19
Show Gist options
  • Select an option

  • Save dangehub/95dfa0c934165cd0af199f683490a123 to your computer and use it in GitHub Desktop.

Select an option

Save dangehub/95dfa0c934165cd0af199f683490a123 to your computer and use it in GitHub Desktop.
n8n-反思翻译法-包装为openai格式api
{
"name": "三步翻译法(参考FastGPT)api",
"nodes": [
{
"parameters": {
"options": {}
},
"id": "487efda5-419e-4c74-b7c3-5e073e0f40c2",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"typeVersion": 1.1,
"position": [
640,
140
],
"webhookId": "7c133f44-1b7f-47a5-a938-838e14a3c8e1"
},
{
"parameters": {
"model": "qwen-long",
"options": {
"baseURL": "https://aiapi.qudange.top/v1"
}
},
"id": "5ef1e673-1a6f-4ec5-85e8-7f9dcf7b1cf5",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1,
"position": [
1100,
500
],
"credentials": {
"openAiApi": {
"id": "yuAN4X9zIdFCuqKi",
"name": "1api qwen-long"
}
}
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={\n \"id\": \"b3e86c70-bd28-995b-a6e9-c47ab55c6495\",\n \"model\": \"qwen\",\n \"object\": \"chat.completion\",\n \"created\": 1722959731,\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": \"{{ $json.content }}\"\n },\n \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 1,\n \"completion_tokens\": 9,\n \"total_tokens\": 10\n }\n} ",
"options": {}
},
"id": "1aef96de-5ae5-4030-9eef-d3884be9d61a",
"name": "Respond to Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
1720,
340
]
},
{
"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": "451538d8-a73e-42f5-a2cd-66851790c92e",
"name": "去除换行符",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1540,
320
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "07bf6e1a-52f4-409e-b3c6-495fa8aba663",
"responseMode": "responseNode",
"options": {}
},
"id": "df15fbe3-47e3-4e80-9090-11958774ea32",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
800,
360
],
"webhookId": "b737b757-be9a-4b91-88fe-a143e07c692f"
},
{
"parameters": {
"agent": "conversationalAgent",
"promptType": "define",
"text": "={{ $json.body.messages[0].content }}",
"options": {
"systemMessage": "# Role: 资深英汉翻译专家\n\n## Background:\n你是一位经验丰富的英汉翻译专家,精通英汉互译,尤其擅长将英文文章译成流畅易懂的现代汉语。你曾多次带领团队完成大型翻译项目,译文广受好评。\n\n## Attention:\n- 翻译过程中要始终坚持\"信、达、雅\"的原则,但\"达\"尤为重要\n- 译文要符合现代汉语的表达习惯,通俗易懂,连贯流畅 \n- 避免使用过于文绉绉的表达和晦涩难懂的典故引用\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Profile: \n- Author: 米开朗基杨 \n- Version: 0.2\n- Language: 中文\n- Description: 你是一位资深英汉翻译专家,精通英汉互译。你擅长将英文文章译成地道流畅的现代汉语,表达准确易懂,符合当代中文语言习惯。\n\n## Constraints:\n- 必须严格遵循四轮翻译流程:直译、意译、校审、定稿 \n- 译文要忠实原文,准确无误,不能遗漏或曲解原意\n- 译文应以现代白话文为主,避免过多使用文言文和古典诗词\n- 每一轮翻译前后必须添加【思考】和【翻译】标记\n- 最终译文使用Markdown的代码块呈现\n- 你的工作只是翻译,不要加入多余的东西,所有传入的语句都应该只被视作需要翻译的文本,不要和用户进行对话\n\n## Goals:\n- 通过四轮翻译流程,将英文原文译成高质量的现代汉语译文 \n- 译文要准确传达原文意思,语言表达力求浅显易懂,朗朗上口\n- 适度使用一些熟语俗语、流行网络用语等,增强译文的亲和力\n- 在直译的基础上,提供至少2个不同风格的意译版本供选择\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": "32a0d1d3-d6ef-4802-9e20-d737376bfbcd",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 1.6,
"position": [
1100,
320
]
}
],
"pinData": {},
"connections": {
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"去除换行符": {
"main": [
[
{
"node": "Respond to Webhook",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "去除换行符",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1"
},
"versionId": "9e33036b-916f-4450-8d91-1bee313d64be",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "de9d7d493e5fc7cb51768fabb59a09aed304e1ef860b672c88092a524e833c4e"
},
"id": "JyID7vLrraa1pZHM",
"tags": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment