Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions internal/translator/gemini_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func assistantMsgToGeminiParts(msg *openai.ChatCompletionAssistantMessageParam)
// }
//
// ].
func openAIToolsToGeminiTools(openaiTools []openai.Tool, parametersJSONSchemaAvailable bool) ([]genai.Tool, error) {
func openAIToolsToGeminiTools(openaiTools []openai.Tool) ([]genai.Tool, error) {
if len(openaiTools) == 0 {
return nil, nil
}
Expand All @@ -448,21 +448,7 @@ func openAIToolsToGeminiTools(openaiTools []openai.Tool, parametersJSONSchemaAva
Description: tool.Function.Description,
}

if parametersJSONSchemaAvailable {
functionDecl.ParametersJsonSchema = tool.Function.Parameters
} else if tool.Function.Parameters != nil {
paramsMap, ok := tool.Function.Parameters.(map[string]any)
if !ok {
return nil, fmt.Errorf("%w: tool %s parameters must be a JSON object", internalapi.ErrInvalidRequestBody, tool.Function.Name)
}

if len(paramsMap) > 0 {
var err error
if functionDecl.Parameters, err = jsonSchemaToGemini(paramsMap); err != nil {
return nil, fmt.Errorf("%w: invalid JSON schema for parameters in tool %s: %w", internalapi.ErrInvalidRequestBody, tool.Function.Name, err)
}
}
}
functionDecl.ParametersJsonSchema = tool.Function.Parameters
functionDecls = append(functionDecls, functionDecl)
}
case openai.ToolTypeImageGeneration:
Expand Down Expand Up @@ -581,11 +567,6 @@ func openAIToolChoiceToGeminiToolConfig(toolChoice *openai.ChatCompletionToolCho
// Check and Update these functions when new Gemini model versions are released
// and their feature support changes.

// it only works with models after gemini2.5 according to https://ai.google.dev/gemini-api/docs/structured-output#json-schema, separate it as a small function to make it easier to maintain
func responseJSONSchemaAvailable(requestModel internalapi.RequestModel) bool {
return strings.Contains(requestModel, "gemini") && (strings.Contains(requestModel, "2.5") || strings.Contains(requestModel, "3"))
}

// mediaResolutionAvailable checks if the model supports media resolution settings.
// Only Gemini 3.0+ models support this feature for controlling image/video quality.
func mediaResolutionAvailable(requestModel internalapi.RequestModel) bool {
Expand Down Expand Up @@ -683,16 +664,7 @@ func openAIReqToGeminiGenerationConfig(openAIReq *openai.ChatCompletionRequest,

responseMode = responseModeJSON

if responseJSONSchemaAvailable(requestModel) {
gc.ResponseJsonSchema = schemaMap
} else {
convertedSchema, err := jsonSchemaToGemini(schemaMap)
if err != nil {
return nil, responseMode, fmt.Errorf("%w: invalid JSON schema: %w", internalapi.ErrInvalidRequestBody, err)
}
gc.ResponseSchema = convertedSchema

}
gc.ResponseJsonSchema = schemaMap
}
}

Expand Down
Loading
Loading