モデルプロバイダー (クラウド)
adk-rust は、adk-model クレートを通じて複数のクラウド Llm プロバイダーをサポートしています。すべてのプロバイダーは Llm トレイトを実装しており、それらを agents で相互に交換可能にします。
概要
┌─────────────────────────────────────────────────────────────────────┐
│ Cloud Model Providers │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ • Gemini (Google) ⭐ Default - Multimodal, large context │
│ • OpenAI (GPT-4o) 🔥 Popular - Best ecosystem │
│ • Anthropic (Claude) 🧠 Smart - Best reasoning │
│ • DeepSeek 💭 Thinking - Chain-of-thought, cheap │
│ • Groq ⚡ Ultra-Fast - Fastest inference │
│ │
│ ローカル/オフラインモデルについては、以下を参照してください: │
│ • Ollama → ollama.md │
│ • mistral.rs → mistralrs.md │
│ │
└─────────────────────────────────────────────────────────────────────┘
クイック比較
| プロバイダー | 最適用途 | 速度 | コスト | 主な特徴 |
|---|---|---|---|---|
| Gemini | 一般的な用途 | ⚡⚡⚡ | 💰 | マルチモーダル、大規模コンテキスト |
| OpenAI | 信頼性 | ⚡⚡ | 💰💰 | 最高のReasoning |
| Anthropic | 複雑な推論 | ⚡⚡ | 💰💰 | 最も安全、最も思慮深い |
| DeepSeek | Chain-of-thought | ⚡⚡ | 💰 | 思考モード、安価 |
| Groq | 速度が重要な用途 | ⚡⚡⚡⚡ | 💰 | 最速の推論 |
ステップ1: インストール
必要なプロバイダーを Cargo.toml に追加します:
[dependencies]
# 1つ以上のプロバイダーを選択してください:
adk-model = { version = "0.2", features = ["gemini"] } # Google Gemini (デフォルト)
adk-model = { version = "0.2", features = ["openai"] } # OpenAI GPT-4o
adk-model = { version = "0.2", features = ["anthropic"] } # Anthropic Claude
adk-model = { version = "0.2", features = ["deepseek"] } # DeepSeek
adk-model = { version = "0.2", features = ["groq"] } # Groq (超高速)
# または、すべてのクラウドプロバイダーを一括で:
adk-model = { version = "0.2", features = ["all-providers"] }
ステップ2: APIキーの設定
export GOOGLE_API_KEY="your-key" # Gemini
export OPENAI_API_KEY="your-key" # OpenAI
export ANTHROPIC_API_KEY="your-key" # Anthropic
export DEEPSEEK_API_KEY="your-key" # DeepSeek
export GROQ_API_KEY="your-key" # Groq
Gemini (Google) ⭐ デフォルト
最適用途: 汎用、マルチモーダルタスク、大規模ドキュメント
主な特徴:
- 🖼️ ネイティブマルチモーダル(画像、動画、音声、PDF)
- 📚 最大2Mトークンのコンテキストウィンドウ
- 💰 競争力のある価格設定
- ⚡ 高速な推論
完全な動作例
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let api_key = std::env::var("GOOGLE_API_KEY")?;
let model = GeminiModel::new(&api_key, "gemini-2.0-flash")?;
let agent = LlmAgentBuilder::new("gemini_assistant")
.description("Gemini-powered assistant")
.instruction("You are a helpful assistant powered by Google Gemini. Be concise.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
利用可能なモデル
| モデル | 説明 | コンテキスト |
|---|---|---|
gemini-2.0-flash | 高速、効率的(推奨) | 1M tokens |
gemini-2.5-flash | 最新のフラッシュモデル | 1M tokens |
gemini-2.5-pro | 最も高性能 | 2M tokens |
出力例
👤 User: What's in this image? [uploads photo of a cat]
🤖 Gemini: I can see a fluffy orange tabby cat sitting on a windowsill.
The cat appears to be looking outside, with sunlight illuminating its fur.
It has green eyes and distinctive striped markings typical of tabby cats.
OpenAI (GPT-4o) 🔥 人気
最適用途: 本番環境アプリ、信頼性の高いパフォーマンス、幅広い機能
主な特徴:
- 🏆 業界標準
- 🔧 優れたツール/関数呼び出し
- 📖 最高のドキュメントとエコシステム
- 🎯 一貫した、予測可能な出力
完全な動作例
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let api_key = std::env::var("OPENAI_API_KEY")?;
let model = OpenAIClient::new(OpenAIConfig::new(&api_key, "gpt-4o"))?;
let agent = LlmAgentBuilder::new("openai_assistant")
.description("OpenAI-powered assistant")
.instruction("You are a helpful assistant powered by OpenAI GPT-4o. Be concise.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
利用可能なモデル
| モデル | 説明 | コンテキスト |
|---|---|---|
gpt-4o | 最も高性能、マルチモーダル | 128K tokens |
gpt-4o-mini | 高速、費用対効果が高い | 128K tokens |
gpt-4-turbo | 以前のフラッグシップ | 128K tokens |
o1 | 推論モデル | 128K tokens |
出力例
👤 User: Write a haiku about Rust programming
🤖 GPT-4o: Memory so safe,
Ownership guards every byte—
Compiler, my friend.
Anthropic (Claude) 🧠 スマート
最適な用途: 複雑な推論、安全性が重視されるアプリケーション、長文ドキュメント
主な特徴:
- 🧠 卓越した推論能力
- 🛡️ 最も安全性に重点を置いている
- 📚 200Kトークンのコンテキスト
- ✍️ 優れた執筆品質
完全な動作例
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let api_key = std::env::var("ANTHROPIC_API_KEY")?;
let model = AnthropicClient::new(AnthropicConfig::new(&api_key, "claude-sonnet-4-20250514"))?;
let agent = LlmAgentBuilder::new("anthropic_assistant")
.description("Anthropic-powered assistant")
.instruction("You are a helpful assistant powered by Anthropic Claude. Be concise and thoughtful.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
利用可能なモデル
| Model | 説明 | コンテキスト |
|---|---|---|
claude-sonnet-4-20250514 | 最新のClaude 4 Sonnet | 200Kトークン |
claude-opus-4-20250514 | 最も高性能なClaude 4 | 200Kトークン |
claude-3-5-sonnet-20241022 | Claude 3.5 Sonnet | 200Kトークン |
出力例
👤 User: Explain quantum entanglement to a 10-year-old
🤖 Claude: Imagine you have two magic coins. When you flip them, they always
land the same way - both heads or both tails - even if one coin is on Earth
and the other is on the Moon! Scientists call this "entanglement." The coins
are connected in a special way that we can't see, like invisible best friends
who always make the same choice at the exact same time.
DeepSeek 💭 思考
最適な用途: 複雑な問題解決、数学、コーディング、推論タスク
主な特徴:
- 💭 Thinking mode - 思考の連鎖的推論を表示
- 💰 非常にコスト効率が高い (GPT-4より10倍安価)
- 🔄 繰り返されるプレフィックス用のコンテキストキャッシュ
- 🧮 数学とコーディングに強い
完全な動作例
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let api_key = std::env::var("DEEPSEEK_API_KEY")?;
// Standard chat model
let model = DeepSeekClient::chat(&api_key)?;
// OR: Reasoning model with thinking mode
// let model = DeepSeekClient::reasoner(&api_key)?;
let agent = LlmAgentBuilder::new("deepseek_assistant")
.description("DeepSeek-powered assistant")
.instruction("You are a helpful assistant powered by DeepSeek. Be concise.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
利用可能なモデル
| Model | 説明 | 特別な機能 |
|---|---|---|
deepseek-chat | 高速チャットモデル | 汎用 |
deepseek-reasoner | 推論モデル | 思考プロセスを表示 |
出力例 (思考モード付きの推論器)
👤 User: What's 17 × 23?
🤖 DeepSeek: <thinking>
Let me break this down:
17 × 23 = 17 × (20 + 3)
= 17 × 20 + 17 × 3
= 340 + 51
= 391
</thinking>
The answer is 391.
Groq ⚡ 超高速
最適: リアルタイムアプリケーション、チャットボット、速度が重要なタスク
主な特徴:
- ⚡ 最速の推論 - 競合他社より10倍高速
- 🔧 LPU (Language Processing Unit) テクノロジー
- 💰 競争力のある価格設定
- 🦙 LLaMA、Mixtral、Gemma モデルを実行
完全な動作例
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
let api_key = std::env::var("GROQ_API_KEY")?;
let model = GroqClient::llama70b(&api_key)?;
let agent = LlmAgentBuilder::new("groq_assistant")
.description("Groq-powered assistant")
.instruction("You are a helpful assistant powered by Groq. Be concise and fast.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
利用可能なモデル
| モデル | メソッド | 説明 |
|---|---|---|
llama-3.3-70b-versatile | GroqClient::llama70b() | 最も高性能 |
llama-3.1-8b-instant | GroqClient::llama8b() | 最速 |
mixtral-8x7b-32768 | カスタム設定 | 良いバランス |
出力例
👤 User: Quick! Name 5 programming languages
🤖 Groq (in 0.2 seconds):
1. Rust
2. Python
3. JavaScript
4. Go
5. TypeScript
プロバイダーの切り替え
すべてのプロバイダーは同じ Llm traitを実装しているため、切り替えは簡単です。
use adk_agent::LlmAgentBuilder;
use std::sync::Arc;
// モデルを変更するだけです - 他はすべて同じままです!
let model: Arc<dyn adk_core::Llm> = Arc::new(
// いずれかを選択:
// GeminiModel::new(&api_key, "gemini-2.0-flash")?
// OpenAIClient::new(OpenAIConfig::new(&api_key, "gpt-4o"))?
// AnthropicClient::new(AnthropicConfig::new(&api_key, "claude-sonnet-4-20250514"))?
// DeepSeekClient::chat(&api_key)?
// GroqClient::llama70b(&api_key)?
);
let agent = LlmAgentBuilder::new("assistant")
.instruction("You are a helpful assistant.")
.model(model)
.build()?;
例
# Gemini (デフォルト)
cargo run --example quickstart
# OpenAI
cargo run --example openai_basic --features openai
# Anthropic
cargo run --example anthropic_basic --features anthropic
# DeepSeek
cargo run --example deepseek_basic --features deepseek
cargo run --example deepseek_reasoner --features deepseek # 思考モード
# Groq
cargo run --example groq_basic --features groq
関連
- Ollama (ローカル) - Ollamaでモデルをローカルで実行する
- ローカルモデル (mistral.rs) - ネイティブRust推論
- LlmAgent - エージェントでモデルを使用する
- Function Tools - エージェントにツールを追加する
前へ: ← Realtime Agents | 次へ: Ollama (ローカル) →