8
n8n 中文网amn8n.com

🗨️ Ollama聊天

中级

这是一个AI领域的自动化工作流,包含 14 个节点。主要使用 Set, ChainLlm, LmOllama, ChatTrigger 等节点,结合人工智能技术实现智能自动化。 🔐🦙🤖 私有本地Ollama自托管AI助手

前置要求
  • AI 服务 API Key(如 OpenAI、Anthropic 等)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "Telr6HU0ltH7s9f7",
  "meta": {
    "instanceId": "31e69f7f4a77bf465b805824e303232f0227212ae922d12133a0f96ffeab4fef"
  },
  "name": "🗨️Ollama 聊天",
  "tags": [],
  "nodes": [
    {
      "id": "9560e89b-ea08-49dc-924e-ec8b83477340",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        280,
        60
      ],
      "webhookId": "4d06a912-2920-489c-a33c-0e3ea0b66745",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "c7919677-233f-4c48-ba01-ae923aef511e",
      "name": "基础LLM链",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "onError": "continueErrorOutput",
      "position": [
        640,
        60
      ],
      "parameters": {
        "text": "=Provide the users prompt and response as a JSON object with two fields:\n- Prompt\n- Response\n\nAvoid any preample or further explanation.\n\nThis is the question: {{ $json.chatInput }}",
        "promptType": "define"
      },
      "typeVersion": 1.5
    },
    {
      "id": "b9676a8b-f790-4661-b8b9-3056c969bdf5",
      "name": "Ollama 模型",
      "type": "@n8n/n8n-nodes-langchain.lmOllama",
      "position": [
        740,
        340
      ],
      "parameters": {
        "model": "llama3.2:latest",
        "options": {}
      },
      "credentials": {
        "ollamaApi": {
          "id": "IsSBWGtcJbjRiKqD",
          "name": "Ollama account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "61dfcda5-083c-43ff-8451-b2417f1e4be4",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        -380
      ],
      "parameters": {
        "color": 4,
        "width": 520,
        "height": 860,
        "content": "# 🦙 Ollama 聊天工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "64f60ee1-7870-461e-8fac-994c9c08b3f9",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        280
      ],
      "parameters": {
        "width": 560,
        "height": 200,
        "content": "## 模型节点"
      },
      "typeVersion": 1
    },
    {
      "id": "bb46210d-450c-405b-a451-42458b3af4ae",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 280,
        "height": 400,
        "content": "## 触发器节点"
      },
      "typeVersion": 1
    },
    {
      "id": "7f21b9e6-6831-4117-a2e2-9c9fb6edc492",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        520,
        -380
      ],
      "parameters": {
        "color": 3,
        "width": 500,
        "height": 620,
        "content": "## 处理节点"
      },
      "typeVersion": 1
    },
    {
      "id": "871bac4e-002f-4a1d-b3f9-0b7d309db709",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 420,
        "height": 200,
        "content": "### 提示(根据您的用例修改)"
      },
      "typeVersion": 1
    },
    {
      "id": "c9e1b2af-059b-4330-a194-45ae0161aa1c",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1060,
        -280
      ],
      "parameters": {
        "color": 5,
        "width": 420,
        "height": 520,
        "content": "## JSON 转对象节点"
      },
      "typeVersion": 1
    },
    {
      "id": "3fb912b8-86ac-42f7-a19c-45e59898a62e",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        -180
      ],
      "parameters": {
        "color": 6,
        "width": 460,
        "height": 420,
        "content": "## 结构化响应节点"
      },
      "typeVersion": 1
    },
    {
      "id": "fdfd1a5c-e1a6-4390-9807-ce665b96b9ae",
      "name": "结构化响应",
      "type": "n8n-nodes-base.set",
      "position": [
        1700,
        60
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "13c4058d-2d50-46b7-a5a6-c788828a1764",
              "name": "text",
              "type": "string",
              "value": "=Your prompt was: {{ $json.response.Prompt }}\n\nMy response is: {{ $json.response.Response }}\n\nThis is the JSON object:\n\n{{ $('Basic LLM Chain').item.json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "76baa6fc-72dd-41f9-aef9-4fd718b526df",
      "name": "错误响应",
      "type": "n8n-nodes-base.set",
      "position": [
        1460,
        660
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "13c4058d-2d50-46b7-a5a6-c788828a1764",
              "name": "text",
              "type": "string",
              "value": "=There was an error."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "bde3b9df-af55-451b-b287-1b5038f9936c",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        280
      ],
      "parameters": {
        "color": 2,
        "width": 540,
        "height": 560,
        "content": "## 错误响应节点"
      },
      "typeVersion": 1
    },
    {
      "id": "b9b2ab8d-9bea-457a-b7bf-51c8ef0de69f",
      "name": "JSON 转对象",
      "type": "n8n-nodes-base.set",
      "position": [
        1220,
        60
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "12af1a54-62a2-44c3-9001-95bb0d7c769d",
              "name": "response",
              "type": "object",
              "value": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5175454a-91b7-4c57-890d-629bd4e8d2fd",
  "connections": {
    "Ollama Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "JSON to Object": {
      "main": [
        [
          {
            "node": "Structured Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "JSON to Object",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 人工智能

需要付费吗?

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

工作流信息
难度等级
中级
节点数量14
分类1
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Joseph LePage

Joseph LePage

@joe

As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.

外部链接
在 n8n.io 查看

分享此工作流