Update Gemini Models (#32902)

Updates google_ai to use latest model information from the respective
model cards: https://ai.google.dev/gemini-api/docs/models

Release Notes:

- google: Update to latest Gemini 2.5 models
This commit is contained in:
Ben Brandt 2025-06-17 22:26:27 +02:00 committed by GitHub
parent 3c9fe363d5
commit 0191f16ebc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 102 additions and 81 deletions

View file

@ -491,33 +491,41 @@ impl<'de> Deserialize<'de> for ModelName {
pub enum Model { pub enum Model {
#[serde(rename = "gemini-1.5-pro")] #[serde(rename = "gemini-1.5-pro")]
Gemini15Pro, Gemini15Pro,
#[serde(rename = "gemini-1.5-flash-8b")]
Gemini15Flash8b,
#[serde(rename = "gemini-1.5-flash")] #[serde(rename = "gemini-1.5-flash")]
Gemini15Flash, Gemini15Flash,
#[serde(rename = "gemini-2.0-pro-exp")]
Gemini20Pro,
#[serde(rename = "gemini-2.0-flash")]
#[default]
Gemini20Flash,
#[serde(rename = "gemini-2.0-flash-thinking-exp")]
Gemini20FlashThinking,
#[serde(rename = "gemini-2.0-flash-lite-preview")]
Gemini20FlashLite,
#[serde(rename = "gemini-2.5-pro-exp-03-25")]
Gemini25ProExp0325,
#[serde(rename = "gemini-2.5-pro-preview-03-25")]
Gemini25ProPreview0325,
#[serde(rename = "gemini-2.5-flash-preview-04-17")]
Gemini25FlashPreview0417,
#[serde( #[serde(
rename = "gemini-2.5-flash-preview-latest", rename = "gemini-2.0-flash-lite",
alias = "gemini-2.5-flash-preview-05-20" alias = "gemini-2.0-flash-lite-preview"
)] )]
Gemini25FlashPreview, Gemini20FlashLite,
#[serde(rename = "gemini-2.0-flash")]
Gemini20Flash,
#[serde( #[serde(
rename = "gemini-2.5-pro-preview-latest", rename = "gemini-2.5-flash-lite-preview",
alias = "gemini-2.5-flash-lite-preview-06-17"
)]
Gemini25FlashLitePreview,
#[serde(
rename = "gemini-2.5-flash",
alias = "gemini-2.0-flash-thinking-exp",
alias = "gemini-2.5-flash-preview-04-17",
alias = "gemini-2.5-flash-preview-05-20",
alias = "gemini-2.5-flash-preview-latest"
)]
#[default]
Gemini25Flash,
#[serde(
rename = "gemini-2.5-pro",
alias = "gemini-2.0-pro-exp",
alias = "gemini-2.5-pro-preview-latest",
alias = "gemini-2.5-pro-exp-03-25",
alias = "gemini-2.5-pro-preview-03-25",
alias = "gemini-2.5-pro-preview-05-06",
alias = "gemini-2.5-pro-preview-06-05" alias = "gemini-2.5-pro-preview-06-05"
)] )]
Gemini25ProPreview, Gemini25Pro,
#[serde(rename = "custom")] #[serde(rename = "custom")]
Custom { Custom {
name: String, name: String,
@ -530,56 +538,47 @@ pub enum Model {
} }
impl Model { impl Model {
pub fn default_fast() -> Model { pub fn default_fast() -> Self {
Model::Gemini20Flash Self::Gemini20FlashLite
} }
pub fn id(&self) -> &str { pub fn id(&self) -> &str {
match self { match self {
Model::Gemini15Pro => "gemini-1.5-pro", Self::Gemini15Pro => "gemini-1.5-pro",
Model::Gemini15Flash => "gemini-1.5-flash", Self::Gemini15Flash8b => "gemini-1.5-flash-8b",
Model::Gemini20Pro => "gemini-2.0-pro-exp", Self::Gemini15Flash => "gemini-1.5-flash",
Model::Gemini20Flash => "gemini-2.0-flash", Self::Gemini20FlashLite => "gemini-2.0-flash-lite",
Model::Gemini20FlashThinking => "gemini-2.0-flash-thinking-exp", Self::Gemini20Flash => "gemini-2.0-flash",
Model::Gemini20FlashLite => "gemini-2.0-flash-lite-preview", Self::Gemini25FlashLitePreview => "gemini-2.5-flash-lite-preview",
Model::Gemini25ProExp0325 => "gemini-2.5-pro-exp-03-25", Self::Gemini25Flash => "gemini-2.5-flash",
Model::Gemini25ProPreview0325 => "gemini-2.5-pro-preview-03-25", Self::Gemini25Pro => "gemini-2.5-pro",
Model::Gemini25FlashPreview0417 => "gemini-2.5-flash-preview-04-17", Self::Custom { name, .. } => name,
Model::Gemini25FlashPreview => "gemini-2.5-flash-preview-latest",
Model::Gemini25ProPreview => "gemini-2.5-pro-preview-latest",
Model::Custom { name, .. } => name,
} }
} }
pub fn request_id(&self) -> &str { pub fn request_id(&self) -> &str {
match self { match self {
Model::Gemini15Pro => "gemini-1.5-pro", Self::Gemini15Pro => "gemini-1.5-pro",
Model::Gemini15Flash => "gemini-1.5-flash", Self::Gemini15Flash8b => "gemini-1.5-flash-8b",
Model::Gemini20Pro => "gemini-2.0-pro-exp", Self::Gemini15Flash => "gemini-1.5-flash",
Model::Gemini20Flash => "gemini-2.0-flash", Self::Gemini20FlashLite => "gemini-2.0-flash-lite",
Model::Gemini20FlashThinking => "gemini-2.0-flash-thinking-exp", Self::Gemini20Flash => "gemini-2.0-flash",
Model::Gemini20FlashLite => "gemini-2.0-flash-lite-preview", Self::Gemini25FlashLitePreview => "gemini-2.5-flash-lite-preview-06-17",
Model::Gemini25ProExp0325 => "gemini-2.5-pro-exp-03-25", Self::Gemini25Flash => "gemini-2.5-flash",
Model::Gemini25ProPreview0325 => "gemini-2.5-pro-preview-03-25", Self::Gemini25Pro => "gemini-2.5-pro",
Model::Gemini25FlashPreview0417 => "gemini-2.5-flash-preview-04-17", Self::Custom { name, .. } => name,
Model::Gemini25FlashPreview => "gemini-2.5-flash-preview-05-20",
Model::Gemini25ProPreview => "gemini-2.5-pro-preview-06-05",
Model::Custom { name, .. } => name,
} }
} }
pub fn display_name(&self) -> &str { pub fn display_name(&self) -> &str {
match self { match self {
Model::Gemini15Pro => "Gemini 1.5 Pro", Self::Gemini15Pro => "Gemini 1.5 Pro",
Model::Gemini15Flash => "Gemini 1.5 Flash", Self::Gemini15Flash8b => "Gemini 1.5 Flash-8b",
Model::Gemini20Pro => "Gemini 2.0 Pro", Self::Gemini15Flash => "Gemini 1.5 Flash",
Model::Gemini20Flash => "Gemini 2.0 Flash", Self::Gemini20FlashLite => "Gemini 2.0 Flash-Lite",
Model::Gemini20FlashThinking => "Gemini 2.0 Flash Thinking", Self::Gemini20Flash => "Gemini 2.0 Flash",
Model::Gemini20FlashLite => "Gemini 2.0 Flash Lite", Self::Gemini25FlashLitePreview => "Gemini 2.5 Flash-Lite Preview",
Model::Gemini25ProExp0325 => "Gemini 2.5 Pro Exp", Self::Gemini25Flash => "Gemini 2.5 Flash",
Model::Gemini25ProPreview0325 => "Gemini 2.5 Pro Preview (0325)", Self::Gemini25Pro => "Gemini 2.5 Pro",
Model::Gemini25FlashPreview0417 => "Gemini 2.5 Flash Preview (0417)",
Model::Gemini25FlashPreview => "Gemini 2.5 Flash Preview",
Model::Gemini25ProPreview => "Gemini 2.5 Pro Preview",
Self::Custom { Self::Custom {
name, display_name, .. name, display_name, ..
} => display_name.as_ref().unwrap_or(name), } => display_name.as_ref().unwrap_or(name),
@ -587,37 +586,55 @@ impl Model {
} }
pub fn max_token_count(&self) -> u64 { pub fn max_token_count(&self) -> u64 {
const ONE_MILLION: u64 = 1_048_576;
const TWO_MILLION: u64 = 2_097_152;
match self { match self {
Model::Gemini15Pro => TWO_MILLION, Self::Gemini15Pro => 2_097_152,
Model::Gemini15Flash => ONE_MILLION, Self::Gemini15Flash8b => 1_048_576,
Model::Gemini20Pro => TWO_MILLION, Self::Gemini15Flash => 1_048_576,
Model::Gemini20Flash => ONE_MILLION, Self::Gemini20FlashLite => 1_048_576,
Model::Gemini20FlashThinking => ONE_MILLION, Self::Gemini20Flash => 1_048_576,
Model::Gemini20FlashLite => ONE_MILLION, Self::Gemini25FlashLitePreview => 1_000_000,
Model::Gemini25ProExp0325 => ONE_MILLION, Self::Gemini25Flash => 1_048_576,
Model::Gemini25ProPreview0325 => ONE_MILLION, Self::Gemini25Pro => 1_048_576,
Model::Gemini25FlashPreview0417 => ONE_MILLION, Self::Custom { max_tokens, .. } => *max_tokens,
Model::Gemini25FlashPreview => ONE_MILLION,
Model::Gemini25ProPreview => ONE_MILLION,
Model::Custom { max_tokens, .. } => *max_tokens,
} }
} }
pub fn max_output_tokens(&self) -> Option<u64> {
match self {
Model::Gemini15Pro => Some(8_192),
Model::Gemini15Flash8b => Some(8_192),
Model::Gemini15Flash => Some(8_192),
Model::Gemini20FlashLite => Some(8_192),
Model::Gemini20Flash => Some(8_192),
Model::Gemini25FlashLitePreview => Some(64_000),
Model::Gemini25Flash => Some(65_536),
Model::Gemini25Pro => Some(65_536),
Model::Custom { .. } => None,
}
}
pub fn supports_tools(&self) -> bool {
true
}
pub fn supports_images(&self) -> bool {
true
}
pub fn mode(&self) -> GoogleModelMode { pub fn mode(&self) -> GoogleModelMode {
match self { match self {
Self::Gemini15Pro Self::Gemini15Pro
| Self::Gemini15Flash8b
| Self::Gemini15Flash | Self::Gemini15Flash
| Self::Gemini20Pro
| Self::Gemini20Flash
| Self::Gemini20FlashThinking
| Self::Gemini20FlashLite | Self::Gemini20FlashLite
| Self::Gemini25ProExp0325 | Self::Gemini20Flash => GoogleModelMode::Default,
| Self::Gemini25ProPreview Self::Gemini25FlashLitePreview | Self::Gemini25Flash | Self::Gemini25Pro => {
| Self::Gemini25FlashPreview GoogleModelMode::Thinking {
| Self::Gemini25ProPreview0325 // By default these models are set to "auto", so we preserve that behavior
| Self::Gemini25FlashPreview0417 => GoogleModelMode::Default, // but indicate they are capable of thinking mode
budget_tokens: None,
}
}
Self::Custom { mode, .. } => *mode, Self::Custom { mode, .. } => *mode,
} }
} }

View file

@ -342,11 +342,11 @@ impl LanguageModel for GoogleLanguageModel {
} }
fn supports_tools(&self) -> bool { fn supports_tools(&self) -> bool {
true self.model.supports_tools()
} }
fn supports_images(&self) -> bool { fn supports_images(&self) -> bool {
true self.model.supports_images()
} }
fn supports_tool_choice(&self, choice: LanguageModelToolChoice) -> bool { fn supports_tool_choice(&self, choice: LanguageModelToolChoice) -> bool {
@ -369,6 +369,10 @@ impl LanguageModel for GoogleLanguageModel {
self.model.max_token_count() self.model.max_token_count()
} }
fn max_output_tokens(&self) -> Option<u64> {
self.model.max_output_tokens()
}
fn count_tokens( fn count_tokens(
&self, &self,
request: LanguageModelRequest, request: LanguageModelRequest,