From 14961bfbc6c546fe8f811b781c739565c80920ae Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Sun, 6 Apr 2025 14:35:22 -0400 Subject: [PATCH] Refactor candidate parsing logic in Google adapter, which fixes only one tool call per execution --- google.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/google.go b/google.go index 59c0883..5c9570f 100644 --- a/google.go +++ b/google.go @@ -121,19 +121,17 @@ func (g google) responseToLLMResponse(in *genai.GenerateContentResponse) (Respon res := Response{} for _, c := range in.Candidates { + var choice ResponseChoice + var set = false if c.Content != nil { for _, p := range c.Content.Parts { switch p.(type) { case genai.Text: - res.Choices = append(res.Choices, ResponseChoice{ - Content: string(p.(genai.Text)), - }) + choice.Content = string(p.(genai.Text)) + set = true case genai.FunctionCall: v := p.(genai.FunctionCall) - choice := ResponseChoice{} - - choice.Content = v.Name b, e := json.Marshal(v.Args) if e != nil { @@ -149,14 +147,17 @@ func (g google) responseToLLMResponse(in *genai.GenerateContentResponse) (Respon } choice.Calls = append(choice.Calls, call) - - res.Choices = append(res.Choices, choice) - + set = true default: return Response{}, fmt.Errorf("unknown part type: %T", p) } } } + + if set { + choice.Role = RoleAssistant + res.Choices = append(res.Choices, choice) + } } return res, nil