gemini: Fix "invalid argument" error when request contains no tools (#28747)

When we do not have any tools, we want to set the `tools` field to
`None`

Release Notes:

- Fixed an issue where Gemini requests would sometimes return a Bad
Request ("Invalid argument...")
This commit is contained in:
Bennet Bo Fenner 2025-04-15 01:57:54 -06:00 committed by GitHub
parent cfc848d24b
commit e1c42315dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -417,7 +417,8 @@ pub fn into_google(
top_k: None,
}),
safety_settings: None,
tools: Some(vec![google_ai::Tool {
tools: (request.tools.len() > 0).then(|| {
vec![google_ai::Tool {
function_declarations: request
.tools
.into_iter()
@ -427,7 +428,8 @@ pub fn into_google(
parameters: tool.input_schema,
})
.collect(),
}]),
}]
}),
tool_config: None,
}
}