KI-Plattformen und Automatisierung
KI-Plattformen und Automatisierungstools helfen Ihnen, schnell KI-Anwendungen und Automatisierungsworkflows zu erstellen und umfangreiche Sprachmodellfunktionen in reale Geschäftsprozesse zu integrieren. Dieser Artikel behandelt die Bereitstellung und Verwendung von Dify, n8n und LangChain/LangGraph unter Ubuntu 26.04.
Verändern
Dify ist eine Open-Source-LLM-Anwendungsentwicklungsplattform, die visuelle Prompt-Orchestrierung, RAG (Retrieval-Augmented Generation), Agent-Workflows und mehr bietet und mehrere Modellanbieter unterstützt.
Systemanforderungen
- Docker und Docker Compose
- Mindestens 4 GB RAM
- Mindestens 20 GB Speicherplatz
Docker Compose-Bereitstellung
# Install Docker (if not already installed)
sudo apt update
sudo apt install -y docker.io docker-compose-v2
sudo usermod -aG docker $USER
newgrp docker
# Clone the Dify repository
git clone https://github.com/langgenius/dify.git
cd dify/docker
# Copy the environment variable configuration file
cp .env.example .env
# Edit the configuration file (modify as needed)
nano .envWichtige Konfigurationselemente:
# Important settings in .env file
# Secret key (must change to a random value)
SECRET_KEY=your-random-secret-key-here
# Database configuration
DB_USERNAME=postgres
DB_PASSWORD=your-secure-password
DB_HOST=db
DB_PORT=5432
DB_DATABASE=dify
# Redis configuration
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=your-redis-password
# Storage configuration
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=storage
# Web configuration
WEB_API_URL=http://localhost/api# Start Dify
docker compose up -d
# Check startup status
docker compose ps
# View logs
docker compose logs -f
# Wait for all services to start (about 1-2 minutes)Greifen Sie auf Dify zu
# Dify web interface defaults to port 80
# Open your browser and visit
# http://localhost
# First visit requires setting up an admin account
# Set email and password, then log inGrundlegende Verwendung
Die wichtigsten Funktionsmodule von Dify:
-
Apps – Erstellen und verwalten Sie KI-Anwendungen
- Chat-Assistent – Erstellen Sie Chatbots
- Textgenerierung – Erstellen Sie Apps zur Textgenerierung
- Agent – Erstellen Sie autonome KI-Agenten
- Workflow – Orchestrieren Sie komplexe KI-Prozesse visuell
-
Wissen – RAG-Funktionalität
- Dokumente hochladen (PDF, Word, Markdown usw.)
- Automatische Segmentierung und Vektorisierung
- Verweisen Sie in Gesprächen auf Inhalte der Wissensdatenbank
-
Modellanbieter – Konfigurieren Sie KI-Modelle
Modellanbieter konfigurieren
Fügen Sie Modelle in den Dify-Einstellungen hinzu:
# Connect OpenAI
# Settings > Model Providers > OpenAI > Enter API Key
# Connect Anthropic (Claude)
# Settings > Model Providers > Anthropic > Enter API Key
# Connect local Ollama
# Settings > Model Providers > Ollama
# Model name: qwen2.5:14b
# Base URL: http://host.docker.internal:11434
# (Use host.docker.internal to access host machine from Docker)Wenn Ollama auf dem Hostcomputer ausgeführt wird, konfigurieren Sie es so, dass der Docker-Containerzugriff möglich ist:
# Modify Ollama listen address
sudo systemctl edit ollama
# Add:
# [Service]
# Environment="OLLAMA_HOST=0.0.0.0:11434"
sudo systemctl restart ollamaDify aktualisieren
cd ~/dify/docker
# Pull latest code
git pull origin main
# Update images and restart
docker compose pull
docker compose down
docker compose up -dSicherungsdaten
# Backup Dify data (database and storage)
cd ~/dify/docker
# Stop services
docker compose down
# Backup data volumes
sudo tar -czf ~/dify-backup-$(date +%Y%m%d).tar.gz \
./volumes/
# Restart services
docker compose up -dDify unterstützt den Aufruf Ihrer erstellten Anwendungen per API. API-Schlüssel und Aufrufbeispiele erhalten Sie in den App-Einstellungen. Das bedeutet, dass Sie KI-Anwendungen in Dify visuell erstellen und diese dann über die API in Ihre eigenen Produkte integrieren können.
n8n
n8n ist ein leistungsstarkes visuelles Workflow-Automatisierungstool mit Hunderten von Integrationsknoten, einschließlich KI-bezogener Knoten (OpenAI, Ollama, Vektordatenbanken usw.), das die Erstellung von KI-Automatisierungsworkflows vereinfacht.
Installieren Sie n8n
Methode 1: Docker-Installation (empfohlen)
# Create data directory
mkdir -p ~/.n8n
# Run n8n with Docker
docker run -d \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
-e N8N_SECURE_COOKIE=false \
--restart always \
n8nio/n8nMethode 2: Docker Installation erstellen
mkdir -p ~/n8n && cd ~/n8n
cat > docker-compose.yml << 'EOF'
services:
n8n:
image: n8nio/n8n
container_name: n8n
ports:
- "5678:5678"
environment:
- N8N_SECURE_COOKIE=false
- GENERIC_TIMEZONE=Asia/Shanghai
volumes:
- n8n_data:/home/node/.n8n
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always
volumes:
n8n_data:
EOF
docker compose up -dMethode 3: Globale npm-Installation
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt install -y nodejs
# Install n8n globally
npm install -g n8n
# Start n8n
n8n start
# Or run in background
n8n start &Greifen Sie auf n8n zu
# Open your browser
# http://localhost:5678
# First visit requires creating an accountBeispiele für KI-Workflows
n8n verfügt über integrierte KI-Knoten zum Aufbau leistungsstarker KI-Automatisierungsworkflows.
Beispiel 1: Automatische Antwort des KI-Kundenservice
Workflow-Knotenverbindungen:
Webhook Trigger -> AI Agent (Claude/GPT) -> Knowledge Base Retrieval -> Generate Reply -> Send ResponseBeispiel 2: Automatische Dokumentzusammenfassung
File Monitor -> Read File -> AI Summary Generation -> Save Result -> Email NotificationBeispiel 3: Lokales Ollama verbinden
Konfigurieren Sie die Ollama-Verbindung in n8n:
- Fügen Sie Ihrem Workflow einen Knoten „Ollama Chat Model“ hinzu
- Erstellen Sie Ollama-Anmeldeinformationen:
- Basis-URL:
http://host.docker.internal:11434(Docker-Umgebung) - Oder
http://localhost:11434(lokale Installation)
- Basis-URL:
- Wählen Sie ein Modell aus (z. B.
qwen2.5:14b)
AI-Knoten in n8n
| Knotentyp | Zweck |
|---|---|
| KI-Agent | Erstellen Sie autonome KI-Agenten |
| OpenAI-Chat-Modell | Stellen Sie eine Verbindung zu OpenAI/kompatiblen APIs her |
| Ollama Chat-Modell | Stellen Sie eine Verbindung zum lokalen Ollama her |
| Anthropisches Chat-Modell | Verbinde dich mit Claude |
| Vector Store | Vektordatenbankoperationen |
| Textsplitter | Textsegmentierung |
| Einbettungen | Textvektorisierung |
| Erinnerung | Konversationsspeicherverwaltung |
| Werkzeug | Benutzerdefinierte KI-Tools |
Erstellen Sie einen AI-Agent-Workflow
1. Add a "When chat message received" trigger
2. Add an "AI Agent" node
3. Connect a model: Add an "Ollama Chat Model" sub-node
4. Add tools:
- "Calculator" -- Math calculations
- "Code" -- Execute code
- "HTTP Request" -- Call APIs
- "Wikipedia" -- Search Wikipedia
5. Add memory: Connect a "Window Buffer Memory" node
6. Save and activate the workflowDie n8n Community Edition (selbstgehostet) ist völlig kostenlos und beinhaltet alle KI-Knoten. n8n Cloud bietet einen gehosteten Dienst mit zusätzlichen Funktionen. Für Einzelpersonen und kleine Teams ist die selbstgehostete Version bereits recht leistungsstark.
LangChain / LangGraph
LangChain ist das führende Entwicklungsframework für die Erstellung von LLM-Anwendungen. LangGraph ist das Teilprojekt, das sich auf die Erstellung zustandsbehafteter, mehrstufiger KI-Agenten-Workflows konzentriert.
Installieren Sie LangChain
# Create a project virtual environment
mkdir -p ~/langchain-project && cd ~/langchain-project
python3 -m venv venv
source venv/bin/activate
# Install LangChain core packages
pip install langchain langchain-core
# Install model provider packages
pip install langchain-anthropic # Claude
pip install langchain-openai # OpenAI
pip install langchain-ollama # Ollama (local models)
# Install LangGraph
pip install langgraph
# Install common tools
pip install langchain-community # Community integrations
pip install langchain-chroma # Chroma vector database
pip install langchain-text-splitters # Text splittingGrundlegendes LangChain-Beispiel
# basic_chain.py
from langchain_ollama import ChatOllama
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
# Use local Ollama model
llm = ChatOllama(model="qwen2.5:14b", base_url="http://localhost:11434")
# Create a prompt template
prompt = ChatPromptTemplate.from_messages([
("system", "You are an Ubuntu Linux expert skilled at answering system administration questions."),
("human", "{question}")
])
# Build the chain
chain = prompt | llm | StrOutputParser()
# Invoke the chain
response = chain.invoke({"question": "How do I check disk usage on Ubuntu?"})
print(response)# Run the example
python basic_chain.pyRAG-Beispiel (Retrieval-Augmented Generation)
# rag_example.py
from langchain_ollama import ChatOllama, OllamaEmbeddings
from langchain_chroma import Chroma
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser
# 1. Prepare documents
documents = [
"Ubuntu 26.04 LTS, codenamed Resolute Raccoon, is scheduled for release on April 23, 2026.",
"Ubuntu uses APT as its package manager. You can install software with apt install.",
"Ubuntu's default desktop environment is GNOME, but it also supports KDE, XFCE, etc.",
"Ubuntu Server edition does not include a graphical interface, making it suitable for server deployments.",
]
# 2. Split text
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=200, chunk_overlap=50
)
splits = text_splitter.create_documents(documents)
# 3. Create vector database
embeddings = OllamaEmbeddings(model="nomic-embed-text")
vectorstore = Chroma.from_documents(splits, embeddings)
retriever = vectorstore.as_retriever()
# 4. Build RAG chain
llm = ChatOllama(model="qwen2.5:14b")
prompt = ChatPromptTemplate.from_template("""
Answer the question based on the following context. If the answer is not in the context, say you don't know.
Context: {context}
Question: {question}
""")
rag_chain = (
{"context": retriever, "question": RunnablePassthrough()}
| prompt
| llm
| StrOutputParser()
)
# 5. Query
result = rag_chain.invoke("What is the codename for Ubuntu 26.04?")
print(result)# Install additional dependencies and run
pip install chromadb
python rag_example.pyBeispiel für einen LangGraph-Agenten
# agent_example.py
from langchain_ollama import ChatOllama
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool
# Define tools
@tool
def search_docs(query: str) -> str:
"""Search Ubuntu documentation for information"""
docs = {
"apt": "APT is Ubuntu's package management tool. Use apt install to install software",
"systemd": "systemd is Ubuntu's service management system. Use systemctl to manage services",
}
for key, value in docs.items():
if key in query.lower():
return value
return "No relevant documentation found"
@tool
def run_command(command: str) -> str:
"""Simulate running a Linux command and return the result"""
return f"Command '{command}' executed (simulated)"
# Create Agent
llm = ChatOllama(model="qwen2.5:14b")
agent = create_react_agent(llm, [search_docs, run_command])
# Run Agent
result = agent.invoke({
"messages": [{"role": "user", "content": "How do I install nginx on Ubuntu?"}]
})
for message in result["messages"]:
print(f"[{message.type}]: {message.content}")LangSmith-Debugging (optional)
# LangSmith provides visual debugging and monitoring for LangChain applications
# Register at https://smith.langchain.com to get an API key
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY="your-langsmith-api-key"
export LANGCHAIN_PROJECT="my-ubuntu-project"
# LangChain code run afterward will automatically report chain data to LangSmithDas Ökosystem von LangChain ist riesig. Anfänger sollten mit einfachen Ketten beginnen und dann schrittweise zu RAG und Agents übergehen. LangGraph eignet sich am besten zum Erstellen komplexer mehrstufiger Agenten. Für einfache Konversationsanwendungen sind einfache LangChain-Ketten ausreichend.
Plattformvergleich
| Funktion | Verändern | n8n | LangChain |
|---|---|---|---|
| Typ | Visuelle Plattform | Workflow-Automatisierung | Entwicklungsrahmen |
| Verwendung | Webschnittstelle | Webschnittstelle | Python-Code |
| Lernkurve | Niedrig | Mittel | Höher |
| Flexibilität | Mittel | Hoch | Sehr hoch |
| RAG-Unterstützung | Eingebaut | Über Knoten | Per Code |
| Agentenunterstützung | Eingebaut | Über KI-Knoten | LangGraph |
| Einsatz | Docker | Docker/npm | Pip |
| Am besten für | Nicht-technische Benutzer | Automatisierungsbegeisterte | Entwickler |
| Open Source | Ja | Ja (Community Edition) | Ja |
Das richtige Werkzeug auswählen
- Möchten Sie KI-Apps schnell und ohne Code erstellen —> Wählen Sie Dify
- KI muss in Automatisierungsworkflows integriert werden —> Wählen Sie n8n
- Benötigen Sie vollständig angepasste KI-Anwendungen und kennen Sie Python —> Wählen Sie LangChain/LangGraph
- Sie können sie kombinieren: Verwenden Sie Dify für Rapid Prototyping, n8n für die Automatisierungsplanung und LangChain für die Kernlogik