Ollama in Automatisierung integrieren
Was dieser Artikel über Ollama-Integrationen behandelt
- Wie Du Ollama in verschiedene Automatisierungstools integrierst.
- Wie n8n, Node-RED, Home Assistant, Nextcloud und Paperless-ngx mit Ollama verbunden werden.
- Praxisbeispiele für Dokumentenverarbeitung, Smart Home und Team-Kollaboration.
- Best Practices für API-Sicherheit, Performance und Zuverlässigkeit.
- Wie Du eigene Integrationen mit der Ollama-API baust.
Einleitung: Ollama-Integrationen verständlich erklärt
Ollama ist ein lokaler Modellserver mit einer REST-API. Jede Software, die HTTP-Requests senden kann, kann Ollama nutzen. Das macht Ollama zu einem universellen KI-Backend für Automatisierungstools. Statt Cloud-APIs zu nutzen, verbindest Du Deine Tools mit Ollama und behältst alle Daten lokal.
Dieser Artikel richtet sich an Anwender, die Ollama in ihre bestehenden Tools integrieren wollen. Du solltest verstehen, wie Ollama funktioniert und was Function Calling ist. Grundlagen der Programmierung findest Du auf IRC-Coding.de.
Warum brauche ich Ollama-Integrationen?
Stell Dir vor, Du nutzt n8n für Workflow-Automatisierung, Home Assistant für Smart Home und Nextcloud für Dokumente. Jedes Tool für sich ist nützlich. Mit Ollama als KI-Backend kannst Du alle Tools mit lokaler KI verbinden: n8n klassifiziert E-Mails, Home Assistant beantwortet Sprachbefehle, Nextcloud fasst Dokumente zusammen. Alles lokal, ohne Cloud, ohne API-Kosten.
Ollama-Integrationen kurz erklärt
Ollama bietet eine REST-API, die jeder Client nutzen kann. Automatisierungstools wie n8n und Node-RED können HTTP-Requests an Ollama senden. Smart-Home-Systeme wie Home Assistant können Ollama über Add-ons nutzen. Dokumenten-Systeme wie Nextcloud und Paperless-ngx können Ollama über Plugins oder Skripte anbinden.
Der Kerngedanke lautet: Ollama ist das KI-Backend, jedes Tool ist der Client.
Für wen ist dieser Artikel gedacht?
- Automatisierer, die Ollama in bestehende Tools integrieren.
- Self-Hoster, die lokale KI in ihre Infrastruktur einbinden.
- Smart-Home-Nutzer, die KI in Home Assistant nutzen.
- Teams, die KI in Nextcloud oder Paperless-ngx einbinden.
Vorkenntnisse in Ollama und grundlegender API-Nutzung sind hilfreich.
Wichtige Begriffe
- Ollama - Lokaler Modellserver. Wann nützlich: das KI-Backend.
- REST-API - HTTP-Schnittstelle. Wann nützlich: wie Tools mit Ollama sprechen.
- n8n - Workflow-Automatisierung. Wann nützlich: für komplexe Workflows.
- Node-RED - Visueller Flow-Editor. Wann nützlich: für visuelle Workflows.
- Home Assistant - Smart-Home-Plattform. Wann nützlich: für Smart-Home-Automatisierung.
- Nextcloud - Self-Hosted Cloud. Wann nützlich: für Dokumentenverwaltung.
- Paperless-ngx - Dokumentenverwaltung. Wann nützlich: für Dokumentenklassifikation.
- Function Calling - Strukturierte KI-Antworten. Wann nützlich: für Tool-Use.
- Docker - Container-Plattform. Wann nützlich: um Tools isoliert zu betreiben.
Ollama-API-Grundlagen
Alle Integrationen nutzen die Ollama-REST-API:
# Chat
curl http://localhost:11434/api/chat -d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "Hallo"}],
"stream": false
}'
# Embeddings
curl http://localhost:11434/api/embeddings -d '{
"model": "nomic-embed-text",
"prompt": "Text für Embedding"
}'
# Function Calling
curl http://localhost:11434/api/chat -d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "Wie ist das Wetter?"}],
"tools": [{"type": "function", "function": {"name": "get_weather", "parameters": {"city": {"type": "string"}}}}],
"stream": false
}'
Siehe Ollama REST API für Details.
Integration 1: Ollama mit n8n
n8n ist ein Workflow-Automatisierungstool, das Ollama über HTTP-Request-Nodes nutzen kann.
Setup
- Ollama läuft auf
http://localhost:11434. - In n8n fügst Du einen HTTP-Request-Node hinzu.
- Konfiguration:
- Method: POST
- URL:
http://localhost:11434/api/chat - Body: JSON
{ "model": "llama3.1", "messages": [{"role": "user", "content": "{{$json.prompt}}"}], "stream": false }
Praxisbeispiel: E-Mail-Klassifikation
// In n8n Function-Node
const email = $input.item.json;
const response = await this.helpers.httpRequest({
method: 'POST',
url: 'http://localhost:11434/api/chat',
body: {
model: 'llama3.1',
messages: [
{ role: 'system', content: 'Klassifiziere in: support, sales, billing, spam.' },
{ role: 'user', content: `Betreff: ${email.subject}\nInhalt: ${email.body}` }
],
stream: false
},
json: true
});
return { category: response.message.content };
Siehe n8n Guide für Details.
Integration 2: Ollama mit Node-RED
Node-RED ist ein visueller Flow-Editor, der Ollama über HTTP-Request-Nodes nutzen kann.
Setup
- Ziehe einen
inject-Node in den Flow. - Ziehe einen
function-Node:msg.payload = { model: "llama3.1", messages: [{ role: "user", content: msg.payload }], stream: false }; msg.headers = { "Content-Type": "application/json" }; return msg; - Ziehe einen
http request-Node:- Method: POST
- URL:
http://localhost:11434/api/chat - Return: parsed JSON
- Verbinde:
inject→function→http request→debug.
Siehe Node-RED für Details.
Integration 3: Ollama mit Home Assistant
Home Assistant ist eine Smart-Home-Plattform, die Ollama über Add-ons oder RESTful-Sensoren nutzen kann.
Setup über RESTful Sensor
# configuration.yaml
sensor:
- platform: rest
name: "KI Antwort"
resource: http://localhost:11434/api/chat
method: POST
payload: |
{
"model": "llama3.1",
"messages": [{"role": "user", "content": "Wie ist das Wetter?"}],
"stream": false
}
value_template: "{{ value_json.message.content }}"
Praxisbeispiel: Sprachassistent
# Shell-Command für Ollama
shell_command:
ollama_chat: >
curl -s http://localhost:11434/api/chat -d '{"model": "llama3.1", "messages": [{"role": "user", "content": "{{ question }}"}], "stream": false}' | jq -r .message.content
# Automation
automation:
- alias: "KI Sprachassistent"
trigger:
- platform: conversation
command: "frage ki [question]"
action:
- service: shell_command.ollama_chat
data:
question: "{{ trigger.question }}"
- service: notify.mobile_app
data:
message: "{{ states('sensor.ki_antwort') }}"
Integration 4: Ollama mit Nextcloud
Nextcloud ist eine Self-Hosted Cloud, die Ollama über Apps oder Skripte nutzen kann.
Setup über Nextcloud App
Es gibt Community-Apps, die Ollama in Nextcloud integrieren. Alternativ kannst Du Skripte nutzen:
// Nextcloud Skript (external app oder occ command)
function callOllama($prompt) {
$client = \OC::$server->getHTTPClientService()->newClient();
$response = $client->post('http://localhost:11434/api/chat', [
'json' => [
'model' => 'llama3.1',
'messages' => [['role' => 'user', 'content' => $prompt]],
'stream' => false
]
]);
return json_decode($response->getBody(), true)['message']['content'];
}
Praxisbeispiel: Dokumentenzusammenfassung
#!/usr/bin/env python3
# Nextcloud Skript: Dokumentenzusammenfassung
import requests
import sys
def summarize_document(content):
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": "llama3.1",
"messages": [
{"role": "system", "content": "Fasse das Dokument in 5 Sätzen zusammen."},
{"role": "user", "content": content[:4000]}
],
"stream": False
}
)
return response.json()["message"]["content"]
if __name__ == "__main__":
content = sys.stdin.read()
print(summarize_document(content))
Integration 5: Ollama mit Paperless-ngx
Paperless-ngx ist eine Dokumentenverwaltung, die Ollama für Klassifikation und Zusammenfassung nutzen kann.
Setup über Custom Script
# paperless-ngx custom script
import requests
def ollama_classify(document_text):
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": "llama3.1",
"messages": [
{"role": "system", "content": "Klassifiziere in: rechnung, vertrag, kunde, sonstiges."},
{"role": "user", "content": document_text[:2000]}
],
"stream": False
}
)
return response.json()["message"]["content"].strip().lower()
# In paperless-ngx Konfiguration
# PAPERLESS_CONSUMER_RECURSIVE=true
# PAPERLESS_CONSUMER_SCRIPT=/path/to/ollama_classify.py
Praxisbeispiel: Automatische Tag-Zuweisung
def ollama_tags(document_text):
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": "llama3.1",
"messages": [
{"role": "system", "content": "Vergib 3-5 Tags für dieses Dokument. Antworte als JSON-Array."},
{"role": "user", "content": document_text[:2000]}
],
"format": "json",
"stream": False
}
)
return response.json()["message"]["content"]
Eigene Integration bauen
Wenn kein fertiges Plugin existiert, kannst Du eigene Integrationen mit der Ollama-API bauen:
import requests
class OllamaClient:
def __init__(self, base_url="http://localhost:11434"):
self.base_url = base_url
def chat(self, model, messages, stream=False):
response = requests.post(
f"{self.base_url}/api/chat",
json={"model": model, "messages": messages, "stream": stream}
)
return response.json()
def embeddings(self, model, prompt):
response = requests.post(
f"{self.base_url}/api/embeddings",
json={"model": model, "prompt": prompt}
)
return response.json()
def chat_with_tools(self, model, messages, tools):
response = requests.post(
f"{self.base_url}/api/chat",
json={"model": model, "messages": messages, "tools": tools, "stream": False}
)
return response.json()
# Verwendung
client = OllamaClient()
response = client.chat("llama3.1", [
{"role": "user", "content": "Hallo"}
])
print(response["message"]["content"])
Sicherheitshinweise
- Ollama absichern: Exponiere Ollama nicht ins Internet ohne Authentifizierung. Siehe API-Schlüssel.
- Netzwerk-Isolation: Nutze Docker-Netzwerke, um Ollama nur für lokale Tools erreichbar zu machen. Siehe Netzwerk-Isolation.
- Keine sensiblen Daten an Cloud: Ollama läuft lokal, aber prüfe, ob Tools Daten an Cloud senden.
- Audit Logging: Protokolliere Ollama-Aufrufe. Siehe Audit Logging.
- Rate-Limits: Ollama hat keine eingebauten Rate-Limits. Schütze vor Überlastung.
Typische Stolpersteine
- Ollama nicht erreichbar: Prüfe, ob Ollama läuft und die URL stimmt.
- Falsches Modell: Prüfe, ob das Modell geladen ist (
ollama list). - Kontextlänge überschritten: Lange Dokumente müssen chunked werden.
- Kein Error-Handling: Wenn Ollama nicht erreichbar ist, sollten Tools nicht abstürzen.
- Sicherheit vergessen: Ollama ohne Authentifizierung ist ein Risiko.
Weiterführende Links
- Ollama REST API - API-Referenz.
- Ollama installieren - Installation.
- n8n Guide - n8n mit Ollama.
- Node-RED - Node-RED mit Ollama.
- Function Calling - Tool-Use.
- API-Schlüssel - Ollama absichern.
- Docker Netzwerk-Isolation - Netzwerk absichern.
Key Takeaways:
- Ollama bietet eine REST-API, die jedes Tool nutzen kann.
- Integrationen: n8n, Node-RED, Home Assistant, Nextcloud, Paperless-ngx.
- Alle Integrationen laufen lokal, ohne Cloud.
- Sicherheit: Ollama absichern, Netzwerk-Isolation, Audit Logging.
- Eigene Integrationen mit der Ollama-API bauen.
FAQ
Welche Tools kann ich mit Ollama integrieren?
Wie verbinde ich Tools mit Ollama?
Wie integriere ich Ollama in n8n?
Wie nutze ich Ollama in Home Assistant?
Wie nutze ich Ollama in Nextcloud?
Wie nutze ich Ollama in Paperless-ngx?
Wie sichere ich Ollama ab?
Wie baue ich eine eigene Integration?
Welches Modell soll ich nutzen?
Was kostet der Betrieb?
Quellen und weiterführende Literatur
- Ollama API - API-Referenz.
- n8n - Workflow-Automatisierung.
- Node-RED - Visueller Flow-Editor.
- Home Assistant - Smart-Home-Plattform.


