Skip to content

Commit 0a2c82e

Browse files
committed
Add example for ListModels
1 parent c9dfa5d commit 0a2c82e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

genai/example_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,27 @@ func ExampleChatSession() {
130130
printResponse(res)
131131
}
132132

133+
func ExampleClient_ListModels() {
134+
ctx := context.Background()
135+
client, err := genai.NewClient(ctx, option.WithAPIKey("your-API-key"))
136+
if err != nil {
137+
log.Fatal(err)
138+
}
139+
defer client.Close()
140+
141+
iter := client.ListModels(ctx)
142+
for {
143+
m, err := iter.Next()
144+
if err == iterator.Done {
145+
break
146+
}
147+
if err != nil {
148+
panic(err)
149+
}
150+
fmt.Println(m.Name, m.Description)
151+
}
152+
}
153+
133154
func printResponse(resp *genai.GenerateContentResponse) {
134155
for _, cand := range resp.Candidates {
135156
for _, part := range cand.Content.Parts {

0 commit comments

Comments
 (0)