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{}
|
res := Response{}
|
||||||
|
|
||||||
for _, c := range in.Candidates {
|
for _, c := range in.Candidates {
|
||||||
|
var choice ResponseChoice
|
||||||
|
var set = false
|
||||||
if c.Content != nil {
|
if c.Content != nil {
|
||||||
for _, p := range c.Content.Parts {
|
for _, p := range c.Content.Parts {
|
||||||
switch p.(type) {
|
switch p.(type) {
|
||||||
case genai.Text:
|
case genai.Text:
|
||||||
res.Choices = append(res.Choices, ResponseChoice{
|
choice.Content = string(p.(genai.Text))
|
||||||
Content: string(p.(genai.Text)),
|
set = true
|
||||||
})
|
|
||||||
|
|
||||||
case genai.FunctionCall:
|
case genai.FunctionCall:
|
||||||
v := p.(genai.FunctionCall)
|
v := p.(genai.FunctionCall)
|
||||||
choice := ResponseChoice{}
|
|
||||||
|
|
||||||
choice.Content = v.Name
|
|
||||||
b, e := json.Marshal(v.Args)
|
b, e := json.Marshal(v.Args)
|
||||||
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@ -149,14 +147,17 @@ func (g google) responseToLLMResponse(in *genai.GenerateContentResponse) (Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
choice.Calls = append(choice.Calls, call)
|
choice.Calls = append(choice.Calls, call)
|
||||||
|
set = true
|
||||||
res.Choices = append(res.Choices, choice)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return Response{}, fmt.Errorf("unknown part type: %T", p)
|
return Response{}, fmt.Errorf("unknown part type: %T", p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if set {
|
||||||
|
choice.Role = RoleAssistant
|
||||||
|
res.Choices = append(res.Choices, choice)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user