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,17 +417,19 @@ pub fn into_google(
top_k: None, top_k: None,
}), }),
safety_settings: None, safety_settings: None,
tools: Some(vec![google_ai::Tool { tools: (request.tools.len() > 0).then(|| {
function_declarations: request vec![google_ai::Tool {
.tools function_declarations: request
.into_iter() .tools
.map(|tool| FunctionDeclaration { .into_iter()
name: tool.name, .map(|tool| FunctionDeclaration {
description: tool.description, name: tool.name,
parameters: tool.input_schema, description: tool.description,
}) parameters: tool.input_schema,
.collect(), })
}]), .collect(),
}]
}),
tool_config: None, tool_config: None,
} }
} }