adk_model/lib.rs
1//! # adk-model
2//!
3//! LLM model integrations for ADK (Gemini, OpenAI, Anthropic, DeepSeek, Groq, Ollama,
4//! Fireworks AI, Together AI, Mistral AI, Perplexity, Cerebras, SambaNova, Amazon Bedrock,
5//! Azure AI Inference).
6//!
7//! ## Overview
8//!
9//! This crate provides LLM implementations for ADK agents. Currently supports:
10//!
11//! - [`GeminiModel`] - Google's Gemini models (3 Pro, 2.5 Flash, etc.)
12//! - `OpenAIClient` - OpenAI models (GPT-5, GPT-5-mini, o3, etc.) — requires `openai` feature
13//! - `AzureOpenAIClient` - Azure OpenAI Service — requires `openai` feature
14//! - `OpenAICompatible` - Any OpenAI-compatible API (xAI, Fireworks, Together, Mistral, Perplexity, Cerebras, SambaNova, or custom) — requires `openai` feature, use `OpenAICompatibleConfig` presets
15//! - `AnthropicClient` - Anthropic Claude models — requires `anthropic` feature
16//! - `DeepSeekClient` - DeepSeek models — requires `deepseek` feature
17//! - `GroqClient` - Groq ultra-fast inference — requires `groq` feature
18//! - `OllamaModel` - Local LLMs via Ollama — requires `ollama` feature
19//! - `BedrockClient` - Amazon Bedrock via AWS SDK — requires `bedrock` feature
20//! - `AzureAIClient` - Azure AI Inference endpoints — requires `azure-ai` feature
21//! - [`MockLlm`] - Mock LLM for testing
22//!
23//! ## Quick Start
24//!
25//! ### Gemini
26//!
27//! ```rust,no_run
28//! use adk_model::GeminiModel;
29//! use std::sync::Arc;
30//!
31//! let api_key = std::env::var("GOOGLE_API_KEY").unwrap();
32//! let model = GeminiModel::new(&api_key, "gemini-2.5-flash").unwrap();
33//! ```
34//!
35//! ### OpenAI
36//!
37//! ```rust,ignore
38//! use adk_model::openai::{OpenAIClient, OpenAIConfig};
39//!
40//! let model = OpenAIClient::new(OpenAIConfig::new(
41//! std::env::var("OPENAI_API_KEY").unwrap(),
42//! "gpt-5-mini",
43//! )).unwrap();
44//! ```
45//!
46//! ### Anthropic
47//!
48//! ```rust,ignore
49//! use adk_model::anthropic::{AnthropicClient, AnthropicConfig};
50//!
51//! let model = AnthropicClient::new(AnthropicConfig::new(
52//! std::env::var("ANTHROPIC_API_KEY").unwrap(),
53//! "claude-sonnet-4-5-20250929",
54//! )).unwrap();
55//! ```
56//!
57//! ### DeepSeek
58//!
59//! ```rust,ignore
60//! use adk_model::deepseek::{DeepSeekClient, DeepSeekConfig};
61//!
62//! // Chat model
63//! let chat = DeepSeekClient::chat(std::env::var("DEEPSEEK_API_KEY").unwrap()).unwrap();
64//!
65//! // Reasoner with thinking mode
66//! let reasoner = DeepSeekClient::reasoner(std::env::var("DEEPSEEK_API_KEY").unwrap()).unwrap();
67//! ```
68//!
69//! ### OpenAI-Compatible Providers (Fireworks, Together, Mistral, Perplexity, Cerebras, SambaNova, xAI)
70//!
71//! All OpenAI-compatible providers use `OpenAICompatible` with provider presets:
72//!
73//! ```rust,ignore
74//! use adk_model::openai_compatible::{OpenAICompatible, OpenAICompatibleConfig};
75//!
76//! // Fireworks AI
77//! let model = OpenAICompatible::new(OpenAICompatibleConfig::fireworks(
78//! std::env::var("FIREWORKS_API_KEY").unwrap(),
79//! "accounts/fireworks/models/llama-v3p1-8b-instruct",
80//! )).unwrap();
81//!
82//! // Together AI
83//! let model = OpenAICompatible::new(OpenAICompatibleConfig::together(
84//! std::env::var("TOGETHER_API_KEY").unwrap(),
85//! "meta-llama/Llama-3.3-70B-Instruct-Turbo",
86//! )).unwrap();
87//!
88//! // Or any custom OpenAI-compatible endpoint
89//! let model = OpenAICompatible::new(
90//! OpenAICompatibleConfig::new("your-api-key", "your-model")
91//! .with_base_url("https://your-endpoint.com/v1")
92//! .with_provider_name("my-provider"),
93//! ).unwrap();
94//! ```
95//!
96//! ### Amazon Bedrock
97//!
98//! ```rust,ignore
99//! use adk_model::bedrock::{BedrockClient, BedrockConfig};
100//!
101//! // Uses AWS IAM credentials from the environment (no API key needed)
102//! let config = BedrockConfig::new("us-east-1", "anthropic.claude-sonnet-4-20250514-v1:0");
103//! let model = BedrockClient::new(config).await.unwrap();
104//! ```
105//!
106//! ### Azure AI Inference
107//!
108//! ```rust,ignore
109//! use adk_model::azure_ai::{AzureAIClient, AzureAIConfig};
110//!
111//! let model = AzureAIClient::new(AzureAIConfig::new(
112//! "https://my-endpoint.eastus.inference.ai.azure.com",
113//! std::env::var("AZURE_AI_API_KEY").unwrap(),
114//! "meta-llama-3.1-8b-instruct",
115//! )).unwrap();
116//! ```
117//!
118//! ### Ollama (Local)
119//!
120//! ```rust,ignore
121//! use adk_model::ollama::{OllamaModel, OllamaConfig};
122//!
123//! // Default: localhost:11434
124//! let model = OllamaModel::new(OllamaConfig::new("llama3.2")).unwrap();
125//! ```
126//!
127//! ## Supported Models
128//!
129//! ### Gemini
130//! | Model | Description |
131//! |-------|-------------|
132//! | `gemini-3-pro-preview` | Most intelligent, complex agentic workflows (1M context) |
133//! | `gemini-3-flash-preview` | Frontier intelligence at Flash speed (1M context) |
134//! | `gemini-2.5-pro` | Advanced reasoning and multimodal (1M context) |
135//! | `gemini-2.5-flash` | Balanced speed and capability, recommended (1M context) |
136//! | `gemini-2.5-flash-lite` | Ultra-fast for high-volume tasks (1M context) |
137//!
138//! ### OpenAI
139//! | Model | Description |
140//! |-------|-------------|
141//! | `gpt-5` | Strongest coding and agentic model with adaptive reasoning |
142//! | `gpt-5-mini` | Efficient variant for most tasks |
143//! | `o3` | Advanced reasoning model for complex problem solving |
144//! | `o4-mini` | Efficient reasoning model (200K context) |
145//! | `gpt-4.1` | General purpose model with 1M context |
146//!
147//! ### Anthropic
148//! | Model | Description |
149//! |-------|-------------|
150//! | `claude-opus-4-5-20251101` | Most capable for complex autonomous tasks |
151//! | `claude-sonnet-4-5-20250929` | Best balance of intelligence, speed, and cost |
152//! | `claude-haiku-4-5-20251001` | Ultra-efficient for high-volume workloads |
153//! | `claude-opus-4-20250514` | Hybrid model with extended thinking |
154//! | `claude-sonnet-4-20250514` | Balanced model with extended thinking |
155//!
156//! ### DeepSeek
157//! | Model | Description |
158//! |-------|-------------|
159//! | `deepseek-chat` | V3.2 non-thinking mode for fast general-purpose tasks |
160//! | `deepseek-reasoner` | V3.2 thinking mode with chain-of-thought reasoning |
161//!
162//! ### Groq
163//! | Model | Description |
164//! |-------|-------------|
165//! | `meta-llama/llama-4-scout-17b-16e-instruct` | Llama 4 Scout via Groq LPU |
166//! | `llama-3.3-70b-versatile` | Versatile large model |
167//! | `llama-3.1-8b-instant` | Ultra-fast at 560 T/s |
168//!
169//! ### OpenAI-Compatible Providers (via `openai` feature)
170//!
171//! Use `OpenAICompatibleConfig` presets — one client, one feature flag:
172//!
173//! | Provider | Preset | Env Var |
174//! |----------|--------|---------|
175//! | Fireworks AI | `OpenAICompatibleConfig::fireworks()` | `FIREWORKS_API_KEY` |
176//! | Together AI | `OpenAICompatibleConfig::together()` | `TOGETHER_API_KEY` |
177//! | Mistral AI | `OpenAICompatibleConfig::mistral()` | `MISTRAL_API_KEY` |
178//! | Perplexity | `OpenAICompatibleConfig::perplexity()` | `PERPLEXITY_API_KEY` |
179//! | Cerebras | `OpenAICompatibleConfig::cerebras()` | `CEREBRAS_API_KEY` |
180//! | SambaNova | `OpenAICompatibleConfig::sambanova()` | `SAMBANOVA_API_KEY` |
181//! | xAI (Grok) | `OpenAICompatibleConfig::xai()` | `XAI_API_KEY` |
182//!
183//! ### Other Providers
184//!
185//! | Provider | Feature Flag | Env Var |
186//! |----------|-------------|---------|
187//! | Amazon Bedrock | `bedrock` | AWS IAM credentials |
188//! | Azure AI Inference | `azure-ai` | `AZURE_AI_API_KEY` |
189//!
190//! ## Features
191//!
192//! - Async streaming with backpressure
193//! - Tool/function calling support
194//! - Multimodal input (text, images, audio, video, PDF)
195//! - Generation configuration (temperature, top_p, etc.)
196//! - OpenAI-compatible APIs (Ollama, vLLM, etc.)
197
198#[cfg(feature = "anthropic")]
199pub mod anthropic;
200pub(crate) mod attachment;
201#[cfg(feature = "azure-ai")]
202pub mod azure_ai;
203#[cfg(feature = "bedrock")]
204pub mod bedrock;
205#[cfg(feature = "deepseek")]
206pub mod deepseek;
207#[cfg(feature = "gemini")]
208pub mod gemini;
209#[cfg(feature = "groq")]
210pub mod groq;
211pub mod mock;
212#[cfg(feature = "ollama")]
213pub mod ollama;
214#[cfg(feature = "openai")]
215pub mod openai;
216#[cfg(feature = "openai")]
217pub mod openai_compatible;
218pub mod provider;
219pub mod retry;
220
221#[cfg(feature = "anthropic")]
222pub use anthropic::AnthropicClient;
223#[cfg(feature = "azure-ai")]
224pub use azure_ai::{AzureAIClient, AzureAIConfig};
225#[cfg(feature = "bedrock")]
226pub use bedrock::{BedrockClient, BedrockConfig};
227#[cfg(feature = "deepseek")]
228pub use deepseek::{DeepSeekClient, DeepSeekConfig};
229#[cfg(feature = "gemini")]
230pub use gemini::GeminiModel;
231#[cfg(feature = "groq")]
232pub use groq::{GroqClient, GroqConfig};
233pub use mock::MockLlm;
234#[cfg(feature = "ollama")]
235pub use ollama::{OllamaConfig, OllamaModel};
236#[cfg(feature = "openai")]
237pub use openai::{AzureConfig, AzureOpenAIClient, OpenAIClient, OpenAIConfig, ReasoningEffort};
238#[cfg(feature = "openai")]
239pub use openai_compatible::{OpenAICompatible, OpenAICompatibleConfig};
240pub use provider::ModelProvider;
241pub use retry::RetryConfig;
242pub use retry::ServerRetryHint;