8
n8n 中文网amn8n.com

多模态聊天助手

高级

这是一个Support Chatbot, AI Chatbot领域的自动化工作流,包含 17 个节点。主要使用 If, Agent, OpenAi, ChainLlm, ChatTrigger 等节点。 基于GPT-4o支持文本、图像和PDF的多模态聊天助手

前置要求
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "SIDZ9gnOf5yEftvX",
  "meta": {
    "instanceId": "406735dbfbf26e97ce8cf19138586c11b62ae90e41ae49e03d25818ac92174c0",
    "templateCredsSetupCompleted": true
  },
  "name": "聊天",
  "tags": [],
  "nodes": [
    {
      "id": "6f6eb820-f3d4-4aa9-b856-1f327650924d",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -882,
        -620
      ],
      "parameters": {
        "text": "=Describe the content of the image or pdf in detail then wait for questions about it. Based on what is in the content, suggest 3 questions the user may ask",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {
          "detail": "high"
        },
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze",
        "binaryPropertyName": "data0"
      },
      "credentials": {
        "openAiApi": {
          "id": "2",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "64b1e72e-ad85-4759-8def-785ca524e468",
      "name": "基础 LLM 链",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -584,
        -520
      ],
      "parameters": {
        "text": "=Describe `{{ $json.content }}`\n\nUse the text from the chat to focus the response:\n`{{ $('chat').item.json.chatInput }}`",
        "batching": {},
        "promptType": "define"
      },
      "typeVersion": 1.7
    },
    {
      "id": "16246a1a-2adb-4b41-809c-64e173738aba",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -496,
        -300
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "2",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "00dafa35-ee47-4c21-8ba6-de6e139b5cba",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -584,
        -20
      ],
      "parameters": {
        "text": "=You are an expert and will help the user with their query `{{ $(\"chat\").item.json.chatInput }}` about\n{{ $json.messages[$json.messages.length - 1].kwargs.content }}\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "39223440-863c-4285-9f27-edf971e953d1",
      "name": "如果",
      "type": "n8n-nodes-base.if",
      "position": [
        -1180,
        -420
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c9a2577d-0589-41ca-9480-2feda2dfbd9b",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.files[0].fileName }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e1970f2b-1a01-4a11-bf65-9b3d9f0e2001",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -436,
        200
      ],
      "parameters": {
        "sessionKey": "={{ $('chat').item.json.sessionId }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "ee3533c1-f12a-4955-bcb8-a0618f80a67c",
      "name": "OpenAI 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -556,
        200
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "2",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2bced281-2c19-407f-ad4b-53075667da17",
      "name": "聊天记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        -584,
        -920
      ],
      "parameters": {
        "mode": "insert",
        "messages": {
          "messageValues": [
            {
              "type": "ai",
              "message": "={{ $json.content }}"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "d5622336-38c3-41f5-880c-a673a90c3ab3",
      "name": "聊天记忆1",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        -960,
        -20
      ],
      "parameters": {
        "options": {},
        "simplifyOutput": false
      },
      "typeVersion": 1.1
    },
    {
      "id": "01d2fa3b-0d56-41a9-ad8a-c79c0038a9b8",
      "name": "简单内存1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -496,
        -700
      ],
      "parameters": {
        "sessionKey": "={{ $(\"chat\").item.json.sessionId }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "417d63c5-3577-446c-844e-bdc9369571f1",
      "name": "聊天",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -1400,
        -420
      ],
      "webhookId": "80032670-58d5-4d08-a1cf-4d1c7aaeca75",
      "parameters": {
        "public": true,
        "options": {
          "allowFileUploads": true
        },
        "initialMessages": ""
      },
      "typeVersion": 1.1
    },
    {
      "id": "9ac78a30-890a-46e7-9148-29795d8ce432",
      "name": "简单记忆2",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -872,
        200
      ],
      "parameters": {
        "sessionKey": "={{ $(\"chat\").item.json.sessionId }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "1e545980-1e75-436d-ad79-a4a434c6a7dd",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        -740
      ],
      "parameters": {
        "width": 340,
        "height": 480,
        "content": "## 与事物对话"
      },
      "typeVersion": 1
    },
    {
      "id": "11295c5b-fa66-4487-807c-2593991b48c0",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1100,
        -740
      ],
      "parameters": {
        "content": "当附加图像/文件/PDF 时运行此路由。它会将所见内容保存到聊天记忆中"
      },
      "typeVersion": 1
    },
    {
      "id": "dee500b2-edba-4639-b505-d0bdec350c0f",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -640
      ],
      "parameters": {
        "content": "使用此节点设置对话"
      },
      "typeVersion": 1
    },
    {
      "id": "ac84b377-ce03-4a19-a5ed-6fd5952e702c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -960,
        -160
      ],
      "parameters": {
        "content": "上传后运行,从内存中检索初始内容"
      },
      "typeVersion": 1
    },
    {
      "id": "3dd32789-a317-44aa-9bc7-2b440a5e57f9",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -140
      ],
      "parameters": {
        "content": "这是主聊天界面,请调整提示词以匹配您的使用场景"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5eb243f1-9afc-48c4-8d1f-d8d091615fab",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "chatmem1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chat": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          },
          {
            "node": "chatmem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chatmem1": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "chatmem",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory2": {
      "ai_memory": [
        [
          {
            "node": "chatmem1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客服机器人, AI 聊天机器人

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流