mirror of
https://github.com/sigoden/aichat
synced 2024-11-08 13:10:28 +00:00
fix: gemini with functions that have empty parameters (#666)
This commit is contained in:
parent
4fbbbd2d99
commit
8b8f8b37c3
@ -353,7 +353,18 @@ pub fn gemini_build_chat_completions_body(
|
||||
}
|
||||
|
||||
if let Some(functions) = functions {
|
||||
body["tools"] = json!([{ "functionDeclarations": *functions }]);
|
||||
// Gemini doesn't support functions with parameters that have empty properties, so we need to patch it.
|
||||
let function_declarations: Vec<_> = functions.into_iter().map(|function| {
|
||||
if function.parameters.is_empty_properties() {
|
||||
json!({
|
||||
"name": function.name,
|
||||
"description": function.description,
|
||||
})
|
||||
} else {
|
||||
json!(function)
|
||||
}
|
||||
}).collect();
|
||||
body["tools"] = json!([{ "functionDeclarations": function_declarations }]);
|
||||
}
|
||||
|
||||
Ok(body)
|
||||
|
@ -125,6 +125,15 @@ pub struct JsonSchema {
|
||||
pub required: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl JsonSchema {
|
||||
pub fn is_empty_properties(&self) -> bool {
|
||||
match &self.properties {
|
||||
Some(v) => v.is_empty(),
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
pub struct ToolCall {
|
||||
pub name: String,
|
||||
|
Loading…
Reference in New Issue
Block a user