diff --git a/core/changelog.md b/core/changelog.md index b27e8a438..ea3185c85 100644 --- a/core/changelog.md +++ b/core/changelog.md @@ -1 +1,2 @@ -- fix: empty string handling in Anthropic provider to prevent sending empty content blocks in chat requests \ No newline at end of file +- fix: empty string handling in Anthropic provider to prevent sending empty content blocks in chat requests +- fix: Gemini/Vertex tool conversion to append all function declarations to a single Tool object \ No newline at end of file diff --git a/core/providers/gemini/responses.go b/core/providers/gemini/responses.go index e6df76648..930cd62c7 100644 --- a/core/providers/gemini/responses.go +++ b/core/providers/gemini/responses.go @@ -2076,12 +2076,10 @@ func (r *GeminiGenerationRequest) convertParamsToGenerationConfigResponses(param // convertResponsesToolsToGemini converts Responses tools to Gemini tools func convertResponsesToolsToGemini(tools []schemas.ResponsesTool) []Tool { - var geminiTools []Tool + geminiTool := Tool{} for _, tool := range tools { if tool.Type == "function" { - geminiTool := Tool{} - // Extract function information from ResponsesExtendedTool if tool.ResponsesToolFunction != nil { if tool.Name != nil && tool.ResponsesToolFunction != nil { @@ -2100,17 +2098,16 @@ func convertResponsesToolsToGemini(tools []schemas.ResponsesTool) []Tool { return nil }(), } - geminiTool.FunctionDeclarations = []*FunctionDeclaration{funcDecl} + geminiTool.FunctionDeclarations = append(geminiTool.FunctionDeclarations, funcDecl) } } - - if len(geminiTool.FunctionDeclarations) > 0 { - geminiTools = append(geminiTools, geminiTool) - } } } - return geminiTools + if len(geminiTool.FunctionDeclarations) > 0 { + return []Tool{geminiTool} + } + return []Tool{} } // convertResponsesToolChoiceToGemini converts Responses tool choice to Gemini tool config diff --git a/core/providers/gemini/utils.go b/core/providers/gemini/utils.go index 5de8fb748..1b05b9373 100644 --- a/core/providers/gemini/utils.go +++ b/core/providers/gemini/utils.go @@ -457,7 +457,7 @@ func convertParamsToGenerationConfig(params *schemas.ChatParameters, responseMod // convertBifrostToolsToGemini converts Bifrost tools to Gemini format func convertBifrostToolsToGemini(bifrostTools []schemas.ChatTool) []Tool { - var geminiTools []Tool + geminiTool := Tool{} for _, tool := range bifrostTools { if tool.Type == "" { @@ -473,14 +473,14 @@ func convertBifrostToolsToGemini(bifrostTools []schemas.ChatTool) []Tool { if tool.Function.Description != nil { fd.Description = *tool.Function.Description } - geminiTool := Tool{ - FunctionDeclarations: []*FunctionDeclaration{fd}, - } - geminiTools = append(geminiTools, geminiTool) + geminiTool.FunctionDeclarations = append(geminiTool.FunctionDeclarations, fd) } } - return geminiTools + if len(geminiTool.FunctionDeclarations) > 0 { + return []Tool{geminiTool} + } + return []Tool{} } // convertFunctionParametersToSchema converts Bifrost function parameters to Gemini Schema diff --git a/core/providers/vertex/vertex_test.go b/core/providers/vertex/vertex_test.go index 977de0236..f46487840 100644 --- a/core/providers/vertex/vertex_test.go +++ b/core/providers/vertex/vertex_test.go @@ -36,7 +36,7 @@ func TestVertex(t *testing.T) { MultiTurnConversation: true, ToolCalls: true, ToolCallsStreaming: true, - MultipleToolCalls: false, // multiple tool calls supported on gemini endpoint only if all tools are search tools + MultipleToolCalls: true, End2EndToolCalling: true, AutomaticFunctionCall: true, ImageURL: true, diff --git a/transports/changelog.md b/transports/changelog.md index 939ca8cfd..db4f0c617 100644 --- a/transports/changelog.md +++ b/transports/changelog.md @@ -1,2 +1,3 @@ - chore: added max_tokens -> max_completion_tokens mapping for chat completions -- fix: empty string handling in Anthropic provider to prevent sending empty content blocks in chat requests \ No newline at end of file +- fix: empty string handling in Anthropic provider to prevent sending empty content blocks in chat requests +- fix: Gemini/Vertex tool conversion to append all function declarations to a single Tool object \ No newline at end of file