AutomationFlowsAI & RAG › AI Chat Handler with Ollama

AI Chat Handler with Ollama

Original n8n title: Ids AI - Chat Handler

IDS AI - Chat Handler. Uses functionItem, lmChatOllama. Webhook trigger; 6 nodes.

Webhook trigger★★★★☆ complexityAI-powered6 nodesFunction ItemOllama Chat
AI & RAG Trigger: Webhook Nodes: 6 Complexity: ★★★★☆ AI nodes: yes Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "IDS AI - Chat Handler",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ids-ai-chat",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// Exercise Detection Function\nconst EXERCISE_KEYWORDS = [\n  'exercise', 'homework', 'assignment', 'quiz', 'exam',\n  'test questions', 'examination', 'worksheet', 'practice problems',\n  'problem set', 'take-home', 'final exam', 'midterm'\n];\n\nconst message = $input.first().json.body.message || '';\nconst context = $input.first().json.body.context || '';\nconst combinedText = (message + ' ' + context).toLowerCase();\n\n// Check for exercise keywords\nlet isExercise = false;\nlet reasons = [];\n\nfor (const keyword of EXERCISE_KEYWORDS) {\n  if (combinedText.includes(keyword)) {\n    isExercise = true;\n    reasons.push(`Contains keyword: ${keyword}`);\n  }\n}\n\n// Check for point patterns\nif (/\\d+\\s*(points?|pts?|marks?)/i.test(combinedText)) {\n  isExercise = true;\n  reasons.push('Contains point/mark values');\n}\n\n// Check for numbered questions\nif (/question\\s*\\d+|problem\\s*\\d+/i.test(combinedText)) {\n  isExercise = true;\n  reasons.push('Contains numbered questions');\n}\n\nreturn [{\n  json: {\n    ...$input.first().json,\n    isExercise,\n    reasons,\n    message,\n    context,\n    conversationId: $input.first().json.body.conversationId || 'new'\n  }\n}];"
      },
      "id": "exercise-filter",
      "name": "Exercise Filter",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.isExercise }}",
              "value2": true
            }
          ]
        }
      },
      "id": "if-exercise",
      "name": "Is Exercise?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"response\": \"I'm sorry, but I cannot help with exercise, homework, quiz, or exam content.\\n\\nThis policy is in place to:\\n- Encourage independent learning and problem-solving\\n- Support academic integrity\\n- Help you develop critical thinking skills\\n\\nIf you have questions about concepts or need help understanding topics, I'd be happy to assist with that instead!\",\n  \"conversationId\": \"{{ $json.conversationId }}\",\n  \"isBlocked\": true,\n  \"blockReason\": \"Exercise content detected\",\n  \"reasons\": {{ JSON.stringify($json.reasons) }}\n}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "reject-exercise",
      "name": "Reject Exercise",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        880,
        180
      ]
    },
    {
      "parameters": {
        "model": "llama3.2:latest",
        "messages": {
          "messageValues": [
            {
              "role": "system",
              "content": "You are IDS AI, an intelligent document assistant. You are helpful, accurate, and concise. You can help users with questions about documents, general knowledge, and various topics. Always be polite and professional.\n\nIMPORTANT: You must NEVER help with exercises, homework, quizzes, exams, or any academic assessment content. If you detect any such content, politely decline and explain why."
            },
            {
              "role": "user",
              "content": "={{ $json.context ? 'Context from uploaded document:\\n' + $json.context + '\\n\\nUser question: ' + $json.message : $json.message }}"
            }
          ]
        },
        "options": {
          "temperature": 0.7,
          "maxTokens": 2048
        }
      },
      "id": "ollama-chat",
      "name": "Ollama Chat",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        880,
        420
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"response\": \"{{ $json.text || $json.message?.content || 'No response generated' }}\",\n  \"conversationId\": \"{{ $node['Exercise Filter'].json.conversationId }}\",\n  \"isBlocked\": false\n}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "send-response",
      "name": "Send Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1100,
        420
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Exercise Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Exercise Filter": {
      "main": [
        [
          {
            "node": "Is Exercise?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Exercise?": {
      "main": [
        [
          {
            "node": "Reject Exercise",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ollama Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "IDS AI"
    }
  ],
  "triggerCount": 0,
  "updatedAt": "2024-12-17T00:00:00.000Z",
  "versionId": "1"
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

IDS AI - Chat Handler. Uses functionItem, lmChatOllama. Webhook trigger; 6 nodes.

Source: https://github.com/yasxai/aimazigh-ai/blob/3665e9f4a45a7441eb5b3d903deece3b1c87026c/n8n-workflows/chat-workflow.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This powerful n8n automation workflow is designed to execute advanced B2B lead enrichment and hyper-personalization for cold email outreach. By orchestrating a complex chain of data scraping, AI analy

OpenAI, HTTP Request, Airtable
AI & RAG

Eu Clara – Funil Kiwify Completo. Uses postgres, openAi, httpRequest, gmail. Webhook trigger; 70 nodes.

Postgres, OpenAI, HTTP Request +1
AI & RAG

This workflow bridges the gap between raw product data and revenue sales tools. It automates the entire Product Qualified Lead (PQL) lifecycle—from real-time intent routing to churn prevention—reducin

HTTP Request, Anthropic, OpenAI
AI & RAG

Lua Nova - Sistema Completo. Uses postgres, httpRequest, openAi. Webhook trigger; 55 nodes.

Postgres, HTTP Request, OpenAI
AI & RAG

User Signup & Verification: The workflow starts when a user signs up. It generates a verification code and sends it via SMS using Twilio. Code Validation: The user replies with the code. The workflow

Postgres, HTTP Request, OpenAI +2