From 656e80920214d767f2d4d6e8ff2e1782ee9f3727 Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Sun, 22 Dec 2024 14:35:21 +0800 Subject: [PATCH] refactor: Simplify Gemini function parameter handling - Removed redundant checks for non-empty properties in function parameters. - Set function parameters to nil when no properties are needed, streamlining the logic for handling Gemini requests. - Improved code clarity and maintainability by eliminating unnecessary complexity. --- relay/channel/gemini/relay-gemini.go | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/relay/channel/gemini/relay-gemini.go b/relay/channel/gemini/relay-gemini.go index 6134b123f..2041d8e75 100644 --- a/relay/channel/gemini/relay-gemini.go +++ b/relay/channel/gemini/relay-gemini.go @@ -56,30 +56,12 @@ 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]} - } + tool.Function.Parameters = nil } } } @@ -105,7 +87,6 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) (*GeminiChatReque }, } } - if textRequest.ResponseFormat != nil && (textRequest.ResponseFormat.Type == "json_schema" || textRequest.ResponseFormat.Type == "json_object") { geminiRequest.GenerationConfig.ResponseMimeType = "application/json"