← all conversations

n8n Ollama Local Workflow

2025-07-173 turns10,808 charsgpt-4-1-mini, gpt-4o1 fork(s)
n8n-workflowollama-integrationlocal-tools

Summary

User wants an n8n workflow JSON that reads a local folder and uses locally hosted Ollama models as tools for defined functions.

Messages

⑂ thread forked here
can you generate an n8n workflow JSON which will read a folder on my computer and then use ollama to perform functions I define as tools and it only uses locally hosted databases
Yes, I can generate a basic `n8n` workflow JSON for you that does the following: - **Monitors a local folder** (e.g., for new files or periodically lists contents) - **Sends file data or content to a locally hosted Ollama instance** (via HTTP node or custom Function) - **Uses custom “tools” you define as LLM functions** through prompt engineering - **Stores all results in a local database** (e.g., SQLite, PostgreSQL, or a file-based store like JSON) --- ### 🔧 Assumptions: - Your local folder is accessible to `n8n` (e.g., `/home/user/watched_folder`) - Ollama is running at `http://localhost:11434/api/generate` - Your Ollama model supports function-style prompt completion (e.g., “tool” selection via instructions) - You are okay with `n8n`'s File node and Function nodes to orchestrate logic - Output will be stored locally using SQLite via the n8n [SQLite node](https://n8n.io/integrations/n8n-nodes-base.sqlite) --- ### 🧠 Example Use Case We’ll define a simple tool system: - Tool: `summarize`, `extract_keywords`, or `classify_topic` --- ### ✅ Step-by-Step Workflow Nodes 1. **Cron Node**: Runs every X minutes 2. **Read Files from Folder**: Get list of files in a directory 3. **Read File Content**: Load file content (assuming .txt or JSON) 4. **Function Node**: Construct prompt for Ollama 5. **HTTP Request to Ollama**: Send prompt 6. **SQLite Node**: Store result --- ### 🧾 n8n Workflow JSON Here's a simplified working version (you can expand it later): ```json { "nodes": [ { "id": "1", "parameters": { "triggerTimes": [ { "mode": "everyMinute" } ] }, "name": "Cron", "type": "n8n-nodes-base.cron", "typeVersion": 1, "position": [250, 300] }, { "id": "2", "parameters": { "directoryPath": "/home/user/watched_folder", "options": { "onlyFiles": true } }, "name": "Read Folder", "type": "n8n-nodes-base.readBinaryFiles", "typeVersion": 1, "position": [450, 300] }, { "id": "3", "parameters": { "options": {} }, "name": "Read File Content", "type": "n8n-nodes-base.file", "typeVersion": 1, "position": [650, 300] }, { "id": "4", "parameters": { "functionCode": "return items.map(item => {\n const fileContent = item.binary.data.toString();\n const prompt = `Choose a tool and apply it to this content:\n\nTOOLS:\n- summarize\n- extract_keywords\n- classify_topic\n\nCONTENT:\n${fileContent}`;\n return {\n json: {\n prompt\n }\n };\n});" }, "name": "Build Prompt", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [850, 300] }, { "id": "5", "parameters": { "url": "http://localhost:11434/api/generate", "method": "POST", "jsonParameters": true, "options": {}, "bodyParametersJson": "={\"model\": \"llama3\", \"prompt\": $json[\"prompt\"], \"stream\": false}" }, "name": "Query Ollama", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [1050, 300] }, { "id": "6", "parameters": { "operation": "executeQuery", "query": "INSERT INTO analysis_results (prompt, result, created_at) VALUES (:prompt, :result, CURRENT_TIMESTAMP);", "values": [ { "name": "prompt", "value": "={{$json[\"prompt\"]}}" }, { "name": "result", "value": "={{$json[\"response\"] || $json[\"data\"]}}" } ], "db": { "database": "local_ollama.db" } }, "name": "Store in SQLite", "type": "n8n-nodes-base.sqlite", "typeVersion": 1, "position": [1250, 300] } ], "connections": { "Cron": { "main": [ [ { "node": "Read Folder", "type": "main", "index": 0 } ] ] }, "Read Folder": { "main": [ [ { "node": "Read File Content", "type": "main", "index": 0 } ] ] }, "Read File Content": { "main": [ [ { "node": "Build Prompt", "type": "main", "index": 0 } ] ] }, "Build Prompt": { "main": [ [ { "node": "Query Ollama", "type": "main", "index": 0 } ] ] }, "Query Ollama": { "main": [ [ { "node": "Store in SQLite", "type": "main", "index": 0 } ] ] } } } ``` --- ### 🪛 Additional Notes - You need to **create the SQLite database and table** manually before running: ```sql CREATE TABLE analysis_results ( id INTEGER PRIMARY KEY AUTOINCREMENT, prompt TEXT, result TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ``` - To define new tools, modify the `prompt` in the Function node. - If your Ollama model accepts function-calling format (like JSON function signatures), I can refactor the workflow to use that instead. --- Would you like the version with: - **Function-calling JSON-style prompts**? - **Separate tools mapped to different flows**? - **Automatic file deletion or archiving after processing?** Let me know and I’ll update the JSON.
gpt-4o
Absolutely! I can help you draft an n8n workflow JSON that: - Reads files from a folder on your local machine - Uses Ollama (local LLM API) as a tool processor, with functions you define - Uses only locally hosted databases (e.g., SQLite or local JSON files) for any data storage or retrieval --- ### Assumptions & Constraints: 1. n8n runs locally on your machine with access to the folder. 2. Ollama provides a local API endpoint for text completion or function calls. 3. The "tools" you want Ollama to perform are predefined and invoked via prompt or function calling. 4. Local databases could be SQLite or local files accessed via n8n nodes (like SQLite node or HTTP Request node to local APIs). 5. No cloud services or external APIs. --- ### Core Workflow Outline: 1. **Read folder contents** (using the *Read Binary Files* node or *Execute Command* node to list files) 2. **For each file**: - Read file content - Send file content or filename to Ollama via HTTP Request node (local API) - Define tools/functions inside the prompt or via function calling if Ollama supports that 3. **Process Ollama output** 4. **Store or update local DB** with results --- ### Sample JSON Workflow Here’s a minimal n8n workflow JSON for this: ```json { "nodes": [ { "parameters": { "command": "ls ./your-folder", "options": {} }, "name": "List Files", "type": "n8n-nodes-base.executeCommand", "typeVersion": 1, "position": [250, 300] }, { "parameters": { "functionCode": "return items[0].json.stdout.split('\\n').filter(f => f.trim() !== '').map(file => ({ json: { filename: file } }));" }, "name": "Split Files", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [450, 300] }, { "parameters": { "path": "./your-folder/{{$json[\"filename\"]}}" }, "name": "Read File", "type": "n8n-nodes-base.readBinaryFile", "typeVersion": 1, "position": [650, 300] }, { "parameters": { "requestMethod": "POST", "url": "http://localhost:11434/api/v1/chat/completions", "jsonParameters": true, "options": {}, "bodyParametersJson": "={\n \"model\": \"ollama-model-name\",\n \"messages\": [\n { \"role\": \"system\", \"content\": \"You are a tool executor. Use the following tools to analyze or modify the file content as per definitions: <define your tools here>\" },\n { \"role\": \"user\", \"content\": $binary.toString($json[\"data\"], 'utf8') }\n ]\n}" }, "name": "Ollama Request", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [850, 300] }, { "parameters": { "query": "INSERT INTO my_local_table (filename, result) VALUES ({{ $json[\"filename\"] }}, {{ $json[\"choices\"][0][\"message\"][\"content\"] }})", "database": "=/path/to/local.db" }, "name": "SQLite Insert", "type": "n8n-nodes-base.sqlite", "typeVersion": 1, "position": [1050, 300] } ], "connections": { "List Files": { "main": [ [ { "node": "Split Files", "type": "main", "index": 0 } ] ] }, "Split Files": { "main": [ [ { "node": "Read File", "type": "main", "index": 0 } ] ] }, "Read File": { "main": [ [ { "node": "Ollama Request", "type": "main", "index": 0 } ] ] }, "Ollama Request": { "main": [ [ { "node": "SQLite Insert", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": {}, "id": "local-folder-ollama-workflow" } ``` --- ### Explanation: - **Execute Command "List Files"** lists files in your folder. - **Function node "Split Files"** splits the output into separate items, each with a filename. - **Read Binary File node** reads the contents of each file. - **HTTP Request node "Ollama Request"** sends the file contents to your locally running Ollama API, including a system prompt where you define your "tools" and their usage instructions. - **SQLite node** stores the filename and the Ollama result locally in a SQLite DB. --- ### What you need to customize: - Replace `./your-folder` with your actual folder path. - Adjust the Ollama API endpoint URL and payload per your Ollama version. - Define your "tools" explicitly in the system message for Ollama. - Update the SQLite DB path and table schema to your needs. - If you use a different local DB, swap the SQLite node accordingly. --- If you want, I can help you further by: - Writing more detailed Ollama system prompts defining your tool functions - Building a schema for your local database - Adjusting the workflow for other local DB types or file formats Just let me know!
gpt-4-1-mini