refactor: Simplify Gemini function parameter handling
Some checks failed
Publish Docker image (amd64) / Push Docker image to multiple registries (push) Has been cancelled
Publish Docker image (arm64) / Push Docker image to multiple registries (push) Has been cancelled
Linux Release / release (push) Has been cancelled
macOS Release / release (push) Has been cancelled
Windows Release / release (push) Has been cancelled
Some checks failed
Publish Docker image (amd64) / Push Docker image to multiple registries (push) Has been cancelled
Publish Docker image (arm64) / Push Docker image to multiple registries (push) Has been cancelled
Linux Release / release (push) Has been cancelled
macOS Release / release (push) Has been cancelled
Windows Release / release (push) Has been cancelled
- 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.
This commit is contained in:
parent
d13103b667
commit
7d0f26c9cd
@ -56,30 +56,12 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) (*GeminiChatReque
|
|||||||
googleSearch = true
|
googleSearch = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Ensure parameters has non-empty properties
|
|
||||||
if tool.Function.Parameters != nil {
|
if tool.Function.Parameters != nil {
|
||||||
params, ok := tool.Function.Parameters.(map[string]interface{})
|
params, ok := tool.Function.Parameters.(map[string]interface{})
|
||||||
if ok {
|
if ok {
|
||||||
if props, hasProps := params["properties"].(map[string]interface{}); hasProps {
|
if props, hasProps := params["properties"].(map[string]interface{}); hasProps {
|
||||||
if len(props) == 0 {
|
if len(props) == 0 {
|
||||||
// Add an empty property if no parameters needed
|
tool.Function.Parameters = nil
|
||||||
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]}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,7 +87,6 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) (*GeminiChatReque
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if textRequest.ResponseFormat != nil && (textRequest.ResponseFormat.Type == "json_schema" || textRequest.ResponseFormat.Type == "json_object") {
|
if textRequest.ResponseFormat != nil && (textRequest.ResponseFormat.Type == "json_schema" || textRequest.ResponseFormat.Type == "json_object") {
|
||||||
geminiRequest.GenerationConfig.ResponseMimeType = "application/json"
|
geminiRequest.GenerationConfig.ResponseMimeType = "application/json"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user