Skip to content

Commit 6c76a67

Browse files
authored
feat(vertexai): add Candidate.FunctionCalls accessor (#10149)
Convenience accessor to align with the Google AI SDK
1 parent 1f9ecc4 commit 6c76a67

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

vertexai/genai/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ func TestLive(t *testing.T) {
257257
t.Fatal(err)
258258
}
259259
part := res.Candidates[0].Content.Parts[0]
260+
funcalls := res.Candidates[0].FunctionCalls()
261+
if len(funcalls) != 1 {
262+
t.Fatalf("got %d FunctionCalls, want 1", len(funcalls))
263+
}
260264
funcall, ok := part.(FunctionCall)
261265
if !ok {
262266
t.Fatalf("want FunctionCall, got %T", part)

vertexai/genai/content.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,17 @@ func (c *GenerationConfig) SetTopP(x float32) { c.TopP = &x }
134134

135135
// SetTopK sets the TopK field.
136136
func (c *GenerationConfig) SetTopK(x int32) { c.TopK = &x }
137+
138+
// FunctionCalls return all the FunctionCall parts in the candidate.
139+
func (c *Candidate) FunctionCalls() []FunctionCall {
140+
if c.Content == nil {
141+
return nil
142+
}
143+
var fcs []FunctionCall
144+
for _, p := range c.Content.Parts {
145+
if fc, ok := p.(FunctionCall); ok {
146+
fcs = append(fcs, fc)
147+
}
148+
}
149+
return fcs
150+
}

0 commit comments

Comments
 (0)