Ollama (ローカルモデル)
LLMsをローカルで、完全なプライバシーで実行できます - APIキーなし、インターネットなし、コストなし。
概要
┌─────────────────────────────────────────────────────────────────────┐
│ Ollama Local Setup │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ Your Machine │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ ADK-Rust │ ───▶ │ Ollama │ │ │
│ │ │ Agent │ │ Server │ │ │
│ │ └──────────────┘ └──────┬───────┘ │ │
│ │ │ │ │
│ │ ┌──────▼───────┐ │ │
│ │ │ Local LLM │ │ │
│ │ │ (llama3.2) │ │ │
│ │ └──────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 🔒 100% Private - Data never leaves your machine │
│ │
└─────────────────────────────────────────────────────────────────────┘
なぜ Ollama?
| 利点 | 説明 |
|---|---|
| 🆓 無料 | APIコストは一切かかりません |
| 🔒 プライベート | データはあなたのマシンに留まります |
| 📴 オフライン | インターネットなしで動作します |
| 🎛️ 制御 | 任意のモデルを選択し、設定をカスタマイズできます |
| ⚡ 高速 | ネットワーク遅延なし |
ステップ 1: Ollama をインストールする
macOS
brew install ollama
Linux
curl -fsSL https://ollama.com/install.sh | sh
Windows
ollama.com からダウンロードしてください。
ステップ 2: サーバーを起動する
ollama serve
次のように表示されるはずです:
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"
ステップ 3: モデルをプルする
新しいターミナルで:
# 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
ステップ 4: プロジェクトに追加する
[dependencies]
adk-model = { version = "2.0.0", features = ["ollama"] }
ステップ 5: コードで使用する
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(())
}
完全な動作例
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"
設定オプション
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)?;
推奨モデル
| モデル | サイズ | 必要なRAM | 最適な用途 |
|---|---|---|---|
llama3.2:3b | 3B | 4GB | 高速、汎用 |
llama3.1:8b | 8B | 8GB | 人気のバランスの取れたモデル |
qwen3.6:35b-a3b | 35B (3B active) | 24GB | 最適なエージェントコーディング — 73.4% SWE-bench |
qwen3.5 | 様々 | 様々 | 強力な多言語対応とコーディング |
qwen3-coder:30b | 30B | 19GB | ツール呼び出しに特化したコード |
qwen2.5:7b | 7B | 8GB | 優れたツール呼び出し、軽量 |
mistral:7b | 7B | 8GB | コードと推論 |
mistral-nemo:12b | 12B | 12GB | 強化されたMistral (128Kコンテキスト) |
deepseek-r1:14b | 14B | 16GB | 蒸留された推論 |
deepseek-r1:32b | 32B | 32GB | より大規模な推論モデル |
gemma3:9b | 9B | 10GB | Googleの効率的なオープンモデル |
devstral:24b | 24B | 24GB | コーディングに最適化 |
codellama:13b | 13B | 16GB | コード生成 |
llama3.3:70b | 70B | 48GB | 最高品質 |
モデルの選択
- RAMが限られている (8GB)? →
llama3.2:3b - 最適なエージェントコーディング? →
qwen3.6:35b-a3b(24GB, MoE — 3Bのみアクティブ) - ツール呼び出しが必要? →
qwen3.5またはqwen3-coder:30b - コードを書く? →
devstral:24bまたはqwen3-coder:30b - 推論が必要? →
deepseek-r1:14bまたはdeepseek-r1:32b - 最高の品質? →
llama3.3:70b(48GB以上のRAMが必要)
Ollamaでのツール呼び出し
Ollamaは互換性のあるモデルでの関数呼び出しをサポートしています:
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()?;
注: ツール呼び出しは、ローカルモデルでの信頼性のために非ストリーミングモードを使用します。
出力例
👤 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!
トラブルシューティング
「Connection refused」
# Make sure Ollama is running
ollama serve
「Model not found」
# Pull the model first
ollama pull llama3.2
応答が遅い
- より小さいモデルを使用する (
llama3.1:70bの代わりにllama3.2) - 他のアプリケーションを閉じてRAMを解放する
- 利用可能であればGPUアクセラレーションを検討する
利用可能なモデルを確認する
ollama list
例の実行
cargo check -p adk-rust --no-default-features --features ollama
ollama serve を実行し、このプロバイダーを使用する Agent を開始する前にモデルをプルしてください。
関連
- Model Providers - クラウドベースの LLM プロバイダー
- Local Models (mistral.rs) - ネイティブRust推論
前へ: ← Model Providers | 次へ: Local Models (mistral.rs) →