优化提示
中级
这是一个Engineering, AI领域的自动化工作流,包含 10 个节点。主要使用 Code, Telegram, Agent, LmChatOpenAi, ExecuteWorkflowTrigger 等节点,结合人工智能技术实现智能自动化。 使用GPT-4o-mini和Telegram投递功能增强AI提示
前置要求
- •Telegram Bot Token
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "heyKyETy1uK0xoX4",
"meta": {
"instanceId": "d00caf92aa0876c596905aea78b35fa33a722cc8e479133822c17064d15c2c1d",
"templateCredsSetupCompleted": true
},
"name": "优化提示",
"tags": [],
"nodes": [
{
"id": "a58be0f5-d11d-4bec-bd8c-0c3a7325b22b",
"name": "当被其他工作流执行时",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-1880,
820
],
"parameters": {
"inputSource": "passthrough"
},
"typeVersion": 1.1
},
{
"id": "67fe408f-e889-4eeb-9e48-f60a579c69f0",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-1600,
720
],
"parameters": {
"text": "={{ $json.query }}",
"options": {
"systemMessage": "Given the user's initial prompt below, please enhance it. Start with a clear, precise instruction at the beginning. Include specific details about the desired context, outcome, length, format, and style. Provide examples of the desired output format, if applicable. Use appropriate leading words or phrases to guide the desired output, especially for code generation. Avoid any vague or imprecise language. Rather than only stating what not to do, provide guidance on what should be done instead. Ensure the revised prompt remains true to the user's original intent. Do not provide examples of desired prompt format, only describe it. Format your response in markdown."
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.7
},
{
"id": "8a041b31-1873-4559-96d0-35d313bffbbd",
"name": "Telegram3",
"type": "n8n-nodes-base.telegram",
"onError": "continueErrorOutput",
"position": [
-1000,
820
],
"webhookId": "4f57022f-14cf-4c3e-b810-ae9395bf3d04",
"parameters": {
"text": "={{ $json.text }}",
"chatId": "={{ $('When Executed by Another Workflow').item.json.chat_id }}",
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "Vh36aBswWhClYxBM",
"name": "Telegram account 2"
}
},
"typeVersion": 1.1
},
{
"id": "5161b177-0663-41c5-b778-ac14756f699c",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1680,
860
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "vIXW5likFrTSZUgz",
"name": "Litellm-account"
}
},
"typeVersion": 1.2
},
{
"id": "d5f36955-74a0-4a9a-b49d-0230d6ee35bf",
"name": "分割成块1",
"type": "n8n-nodes-base.code",
"position": [
-1180,
820
],
"parameters": {
"jsCode": "// Get the entire output of the previous node\nlet text = $input.all() || '';\n\n// Convert the output to a string if it's not already\nif (typeof text !== 'string') {\n text = JSON.stringify(text, null, 2); // Pretty-print JSON objects\n}\n\n// Replace multiple newlines (\\n\\n+) with a single newline (\\n)\ntext = text.replace(/\\n{2,}/g, '\\n');\n\nconst maxLength = 3072; // Telegram message character limit\nconst messages = [];\n\n// Add an optional header for the first chunk\nconst header = `# Optimized prompt\\n\\n`;\nlet currentText = header + text;\n\n// Split the output into chunks of maxLength without splitting words\nwhile (currentText.length > 0) {\n let chunk = currentText.slice(0, maxLength);\n\n // Ensure we don't split in the middle of a word\n if (chunk.length === maxLength && currentText[maxLength] !== ' ') {\n const lastSpaceIndex = chunk.lastIndexOf(' ');\n if (lastSpaceIndex > -1) {\n chunk = chunk.slice(0, lastSpaceIndex);\n }\n }\n\n messages.push(chunk.trim()); // Trim extra whitespace for cleaner output\n currentText = currentText.slice(chunk.length).trim(); // Remove the chunk from the remaining text\n}\n\n// Return the split messages in Markdown format\nreturn messages.map((chunk) => ({ json: { text: `\\`\\`\\`markdown\\n${chunk}\\n\\`\\`\\`` } }));\n"
},
"typeVersion": 2
},
{
"id": "b22f3481-caeb-4506-8fe0-c7e2597772b9",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"disabled": true,
"position": [
-2120,
600
],
"parameters": {
"color": 5,
"width": 389,
"height": 381,
"content": "## 触发器"
},
"typeVersion": 1
},
{
"id": "2bf7ebcc-2d34-4c56-b9de-c930ccb4f30f",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"disabled": true,
"position": [
-1720,
600
],
"parameters": {
"color": 6,
"width": 489,
"height": 381,
"content": "# 推理/优化"
},
"typeVersion": 1
},
{
"id": "ccc5f97e-6215-41fc-9633-f57857743282",
"name": "简单记忆",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
-1340,
860
],
"parameters": {},
"typeVersion": 1.3
},
{
"id": "3bfb31b6-add3-4d5b-989e-df88d69e07e8",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"disabled": true,
"position": [
-1220,
600
],
"parameters": {
"width": 349,
"height": 381,
"content": "# 改进后的提示:"
},
"typeVersion": 1
},
{
"id": "a36fdc9d-d000-4120-99e8-53d49edec74a",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"disabled": true,
"position": [
-2120,
1000
],
"parameters": {
"color": 7,
"width": 1249,
"height": 541,
"content": "# 工作流文档"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "05beb500-d266-45e7-8f5a-ad3a8c9a72e1",
"connections": {
"AI Agent": {
"main": [
[
{
"node": "Split into chunks1",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Split into chunks1": {
"main": [
[
{
"node": "Telegram3",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 工程, 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
代理访问控制模板
使用Airtable和Telegram的AI代理访问控制(RBAC)
If
Set
Airtable
+13
36 节点Mario
工程
使用OpenAI、Wikipedia、Google搜索和Gmail/Telegram自动生成研究报告
AI、维基百科、搜索与Gmail/Telegram的自动化研究报告生成
If
Code
Gmail
+14
26 节点Immanuel
人工智能
股市技术分析
使用 GPT-4o 和 TradingView 为 Telegram 提供股市技术分析
Set
Code
Telegram
+9
16 节点Badr
财务
技术雷达
使用SQL数据库、RAG和路由代理构建AI驱动的技术雷达顾问
If
Code
Cron
+22
53 节点Sean Lon
工程
AI智能助手与Airtable对话及数据分析
AI智能助手与Airtable对话及数据分析
If
Set
Merge
+12
41 节点Mark Shcherbakov
工程
基于 Bright Data MCP 的 AI Telegram 数据提取机器人
集成 Bright Data MCP 的 AI Telegram 数据提取机器人
If
N8n
Wait
+11
21 节点Cyril Nicko Gaspar
工程