Refactor candidate parsing logic in Google adapter, which fixes only one tool call per execution
This commit is contained in:
parent
7c9eb08cb4
commit
14961bfbc6
19
google.go
19
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user