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
42 changes: 30 additions & 12 deletions providers/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ func (g languageModel) prepareParams(call fantasy.Call) (*genai.GenerateContentC
}
}

systemInstructions, content, warnings := toGooglePrompt(call.Prompt)
isVertexAI := g.providerOptions.backend == genai.BackendVertexAI
systemInstructions, content, warnings := toGooglePrompt(call.Prompt, isVertexAI)

if providerOptions.ThinkingConfig != nil {
if providerOptions.ThinkingConfig.IncludeThoughts != nil &&
Expand Down Expand Up @@ -347,7 +348,7 @@ func (g languageModel) prepareParams(call fantasy.Call) (*genai.GenerateContentC
return config, content, warnings, nil
}

func toGooglePrompt(prompt fantasy.Prompt) (*genai.Content, []*genai.Content, []fantasy.CallWarning) { //nolint: unparam
func toGooglePrompt(prompt fantasy.Prompt, isVertexAI bool) (*genai.Content, []*genai.Content, []fantasy.CallWarning) { //nolint: unparam
var systemInstructions *genai.Content
var content []*genai.Content
var warnings []fantasy.CallWarning
Expand Down Expand Up @@ -462,6 +463,11 @@ func toGooglePrompt(prompt fantasy.Prompt) (*genai.Content, []*genai.Content, []
Args: result,
},
}

// Vertex breaks with a 400 if this field be present.
if isVertexAI {
geminiPart.FunctionCall.ID = ""
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
geminiPart := &genai.Part{
FunctionCall: &genai.FunctionCall{
ID: toolCall.ToolCallID,
Name: toolCall.ToolName,
Args: result,
},
}
// Vertex breaks with a 400 if this field be present.
if isVertexAI {
geminiPart.FunctionCall.ID = ""
}
}

if currentReasoningMetadata != nil {
geminiPart.ThoughtSignature = []byte(currentReasoningMetadata.Signature)
currentReasoningMetadata = nil
Expand Down Expand Up @@ -506,12 +512,18 @@ func toGooglePrompt(prompt fantasy.Prompt) (*genai.Content, []*genai.Content, []
continue
}
response := map[string]any{"result": content.Text}
functionResponse := &genai.FunctionResponse{
ID: result.ToolCallID,
Response: response,
Name: toolCall.ToolName,
}

// Vertex breaks with a 400 if this field be present.
if isVertexAI {
functionResponse.ID = ""
}
parts = append(parts, &genai.Part{
FunctionResponse: &genai.FunctionResponse{
ID: result.ToolCallID,
Response: response,
Name: toolCall.ToolName,
},
FunctionResponse: functionResponse,
})

case fantasy.ToolResultContentTypeError:
Expand All @@ -520,12 +532,18 @@ func toGooglePrompt(prompt fantasy.Prompt) (*genai.Content, []*genai.Content, []
continue
}
response := map[string]any{"result": content.Error.Error()}
functionResponse := &genai.FunctionResponse{
ID: result.ToolCallID,
Response: response,
Name: toolCall.ToolName,
}

// Vertex breaks with a 400 if this field be present.
if isVertexAI {
functionResponse.ID = ""
}
parts = append(parts, &genai.Part{
FunctionResponse: &genai.FunctionResponse{
ID: result.ToolCallID,
Response: response,
Name: toolCall.ToolName,
},
FunctionResponse: functionResponse,
})
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading