From 53ab2aaee42ff846a454d558395b23320e79c008 Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Sun, 22 Dec 2024 14:29:14 +0800 Subject: [PATCH] feat: Enhance Gemini function parameter handling - Added logic to ensure that function parameters have non-empty properties. - Implemented checks to add a default empty property if no parameters are needed. - Updated the required field to match existing properties, improving the robustness of the Gemini function integration. --- relay/channel/gemini/relay-gemini.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/relay/channel/gemini/relay-gemini.go b/relay/channel/gemini/relay-gemini.go index 177863268..6134b123f 100644 --- a/relay/channel/gemini/relay-gemini.go +++ b/relay/channel/gemini/relay-gemini.go @@ -56,6 +56,34 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) (*GeminiChatReque googleSearch = true continue } + // Ensure parameters has non-empty properties + if tool.Function.Parameters != nil { + params, ok := tool.Function.Parameters.(map[string]interface{}) + if ok { + if props, hasProps := params["properties"].(map[string]interface{}); hasProps { + if len(props) == 0 { + // Add an empty property if no parameters needed + params["properties"] = map[string]interface{}{ + "_": map[string]interface{}{ + "type": "string", + "description": "No parameters needed", + }, + } + // Update required field to match the property + params["required"] = []string{"_"} + } else { + // If properties exist, ensure required field matches existing properties + existingProps := make([]string, 0) + for propName := range props { + existingProps = append(existingProps, propName) + } + if len(existingProps) > 0 { + params["required"] = []string{existingProps[0]} + } + } + } + } + } functions = append(functions, tool.Function) } if len(functions) > 0 {