From 48eb6e8fdae94a5a38d08006e85b1cacf996e4f4 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 15 Jan 2025 15:40:35 -0600 Subject: [PATCH 1/2] fix gemini function call --- .../Providers/Chat/GeminiChatCompletionProvider.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs index 11ea8f18..877070cd 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs @@ -126,18 +126,18 @@ public class GeminiChatCompletionProvider : IChatCompletion if (!agentService.RenderFunction(agent, function)) continue; var def = agentService.RenderFunctionProperty(agent, function); - var str = JsonSerializer.Serialize(def.Properties); + var str = JsonSerializer.Serialize(def?.Properties); funcDeclarations.Add(new FunctionDeclaration { Name = function.Name, Description = function.Description, - Parameters = new() + Parameters = str != "{}" ? new() { - Type = str != "{}" ? ParameterType.Object : ParameterType.TypeUnspecified, - Properties = str != "{}" ? JsonSerializer.Deserialize(str) : null, - Required = def.Required - } + Type = ParameterType.Object, + Properties = JsonSerializer.Deserialize(str), + Required = def?.Required ?? [] + } : null }); funcPrompts.Add($"{function.Name}: {function.Description} {def}"); From 90c2bd75dfdf7aa0c8c01ca4519fa8f7ca56dcc8 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 15 Jan 2025 15:46:03 -0600 Subject: [PATCH 2/2] refine gemini function parameter --- .../Chat/GeminiChatCompletionProvider.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs index 877070cd..5930a6b9 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Chat/GeminiChatCompletionProvider.cs @@ -126,18 +126,19 @@ public class GeminiChatCompletionProvider : IChatCompletion if (!agentService.RenderFunction(agent, function)) continue; var def = agentService.RenderFunctionProperty(agent, function); - var str = JsonSerializer.Serialize(def?.Properties); + var props = JsonSerializer.Serialize(def?.Properties); + var parameters = !string.IsNullOrWhiteSpace(props) && props != "{}" ? new Schema() + { + Type = ParameterType.Object, + Properties = JsonSerializer.Deserialize(props), + Required = def?.Required ?? [] + } : null; funcDeclarations.Add(new FunctionDeclaration { Name = function.Name, Description = function.Description, - Parameters = str != "{}" ? new() - { - Type = ParameterType.Object, - Properties = JsonSerializer.Deserialize(str), - Required = def?.Required ?? [] - } : null + Parameters = parameters }); funcPrompts.Add($"{function.Name}: {function.Description} {def}");