Ollama (Lokale Modelle)
Führen Sie LLMs lokal mit vollständiger Privatsphäre aus – keine API-Schlüssel, kein Internet, keine Kosten.
Übersicht
┌─────────────────────────────────────────────────────────────────────┐
│ Ollama Local Setup │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ Your Machine │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ ADK-Rust │ ───▶ │ Ollama │ │ │
│ │ │ Agent │ │ Server │ │ │
│ │ └──────────────┘ └──────┬───────┘ │ │
│ │ │ │ │
│ │ ┌──────▼───────┐ │ │
│ │ │ Local LLM │ │ │
│ │ │ (llama3.2) │ │ │
│ │ └──────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 🔒 100% Private - Data never leaves your machine │
│ │
└─────────────────────────────────────────────────────────────────────┘
Warum Ollama?
| Vorteil | Beschreibung |
|---|---|
| 🆓 Kostenlos | Keine API-Kosten, jemals |
| 🔒 Privat | Daten bleiben auf Ihrem Rechner |
| 📴 Offline | Funktioniert ohne Internet |
| 🎛️ Kontrolle | Wählen Sie ein beliebiges Modell, passen Sie Einstellungen an |
| ⚡ Schnell | Keine Netzwerklatenz |
Schritt 1: Ollama installieren
macOS
brew install ollama
Linux
curl -fsSL https://ollama.com/install.sh | sh
Windows
Herunterladen von ollama.com
Schritt 2: Den Server starten
ollama serve
Sie sollten sehen:
Couldn't find '/Users/you/.ollama/id_ed25519'. Generating new private key.
Your new public key is: ssh-ed25519 AAAA...
time=2024-01-05T12:00:00.000Z level=INFO source=server.go msg="Listening on 127.0.0.1:11434"
Schritt 3: Ein Modell herunterladen
In einem neuen Terminal:
# Recommended starter model (3B parameters, fast)
ollama pull llama3.2:3b
# Other popular models
ollama pull qwen3.6:35b-a3b # Latest Qwen — 73.4% SWE-bench, MoE 35B/3B active
ollama pull qwen3.5 # Strong multilingual and coding
ollama pull qwen3-coder:30b # Code-focused with tool calling
ollama pull mistral:7b # Good for code
ollama pull deepseek-r1:14b # Reasoning model
ollama pull devstral:24b # Optimized for coding
ollama pull gemma3:9b # Google's efficient model
ollama pull codellama:13b # Code generation
Schritt 4: Zu Ihrem Projekt hinzufügen
[dependencies]
adk-model = { version = "2.0.0", features = ["ollama"] }
Schritt 5: Im Code verwenden
use adk_model::ollama::{OllamaModel, OllamaConfig};
use adk_agent::LlmAgentBuilder;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// No API key needed!
let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;
let agent = LlmAgentBuilder::new("local_assistant")
.instruction("You are a helpful assistant running locally.")
.model(Arc::new(model))
.build()?;
// Use the agent...
Ok(())
}
Vollständiges funktionierendes Beispiel
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
// No API key needed!
let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;
let agent = LlmAgentBuilder::new("ollama_assistant")
.description("Ollama-powered local assistant")
.instruction("You are a helpful assistant running locally via Ollama. Be concise.")
.model(Arc::new(model))
.build()?;
// Run interactive session
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
Cargo.toml
[dependencies]
adk-rust = { version = "2.0.0", features = ["ollama"] }
tokio = { version = "1", features = ["full"] }
dotenvy = "0.15"
anyhow = "1.0"
Konfigurationsoptionen
use adk_model::ollama::{OllamaModel, OllamaConfig};
let config = OllamaConfig::new("llama3.2")
.with_base_url("http://localhost:11434") // Custom server URL
.with_temperature(0.7) // Creativity (0.0-1.0)
.with_max_tokens(2048); // Max response length
let model = OllamaModel::new(config)?;
Empfohlene Modelle
| Modell | Größe | Benötigter RAM | Am besten geeignet für |
|---|---|---|---|
llama3.2:3b | 3B | 4GB | Schnell, Allzweck |
llama3.1:8b | 8B | 8GB | Beliebtes, ausgewogenes Modell |
qwen3.6:35b-a3b | 35B (3B active) | 24GB | Beste agentische Codierung — 73.4% SWE-bench |
qwen3.5 | varies | varies | Stark mehrsprachig und Codierung |
qwen3-coder:30b | 30B | 19GB | Code-fokussiert mit Tool-Aufruf |
qwen2.5:7b | 7B | 8GB | Guter Tool-Aufruf, leichtgewichtig |
mistral:7b | 7B | 8GB | Code und Argumentation |
mistral-nemo:12b | 12B | 12GB | Verbessertes Mistral (128K Kontext) |
deepseek-r1:14b | 14B | 16GB | Destillierte Argumentation |
deepseek-r1:32b | 32B | 32GB | Größeres Argumentationsmodell |
gemma3:9b | 9B | 10GB | Googles effizientes offenes Modell |
devstral:24b | 24B | 24GB | Optimiert für Codierung |
codellama:13b | 13B | 16GB | Codegenerierung |
llama3.3:70b | 70B | 48GB | Höchste Qualität |
Modell auswählen
- Begrenzter RAM (8GB)? →
llama3.2:3b - Beste agentische Codierung? →
qwen3.6:35b-a3b(24GB, MoE — only 3B active) - Benötigen Sie Tool Calling? →
qwen3.5oderqwen3-coder:30b - Code schreiben? →
devstral:24boderqwen3-coder:30b - Benötigen Sie Argumentation? →
deepseek-r1:14boderdeepseek-r1:32b - Beste Qualität? →
llama3.3:70b(benötigt 48GB+ RAM)
Tool Calling mit Ollama
Ollama unterstützt Funktion calling mit kompatiblen Modellen:
use adk_model::ollama::{OllamaModel, OllamaConfig};
use adk_agent::LlmAgentBuilder;
use adk_tool::FunctionTool;
use std::sync::Arc;
// qwen2.5 has excellent tool calling support
let model = OllamaModel::new(OllamaConfig::new("qwen2.5:7b"))?;
let weather_tool = Arc::new(FunctionTool::new(
"get_weather",
"Get weather for a location",
|_ctx, args| async move {
let location = args.get("location").and_then(|v| v.as_str()).unwrap_or("unknown");
Ok(serde_json::json!({
"location": location,
"temperature": "72°F",
"condition": "Sunny"
}))
},
));
let agent = LlmAgentBuilder::new("weather_assistant")
.instruction("Help users check the weather.")
.model(Arc::new(model))
.tool(weather_tool)
.build()?;
Hinweis: Tool calling verwendet den Nicht-Streaming-Modus für Zuverlässigkeit mit lokalen Modellen.
Beispielausgabe
👤 User: Hello! What can you do?
🤖 Ollama (llama3.2): Hello! I'm a local AI assistant running on your
machine. I can help with:
- Answering questions
- Writing and editing text
- Explaining concepts
- Basic coding help
All completely private - nothing leaves your computer!
Fehlerbehebung
"Verbindung verweigert"
# Make sure Ollama is running
ollama serve
"Modell nicht gefunden"
# Pull the model first
ollama pull llama3.2
Langsame Antworten
- Verwenden Sie ein kleineres Modell (
llama3.2anstelle vonllama3.1:70b) - Schließen Sie andere Anwendungen, um RAM freizugeben
- Ziehen Sie eine GPU-Beschleunigung in Betracht, falls verfügbar
Verfügbare Modelle prüfen
ollama list
Beispiele ausführen
cargo check -p adk-rust --no-default-features --features ollama
Führen Sie ollama serve aus und laden Sie das Modell, bevor Sie einen Agent starten, der diesen Anbieter verwendet.
Verwandt
- Model Providers - Cloud-basierte LLM-Anbieter
- Local Models (mistral.rs) - Native Rust-Inferenz
Zurück: ← Model Providers | Weiter: Local Models (mistral.rs) →