Skip to content

Commit bc02fa3

Browse files
committed
feat(genai): Add generate content with routing option
1 parent b6845ed commit bc02fa3

17 files changed

+42
-22
lines changed

genai/controlled_generation/ctrlgen_with_enum_schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func generateWithEnumSchema(w io.Writer) error {
3939
contents := []*genai.Content{
4040
{Parts: []*genai.Part{
4141
{Text: "What type of instrument is an oboe?"},
42-
}},
42+
}, Role: "user"},
4343
}
4444
config := &genai.GenerateContentConfig{
4545
ResponseMIMEType: "text/x.enum",

genai/controlled_generation/ctrlgen_with_nullable_schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ Finally, Saturday rounds off the week with sunny skies, a temperature of 80°F,
4949
contents := []*genai.Content{
5050
{Parts: []*genai.Part{
5151
{Text: prompt},
52-
}},
52+
},
53+
Role: "user"},
5354
}
5455
config := &genai.GenerateContentConfig{
5556
ResponseMIMEType: "application/json",

genai/controlled_generation/ctrlgen_with_resp_schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func generateWithRespSchema(w io.Writer) error {
5757
contents := []*genai.Content{
5858
{Parts: []*genai.Part{
5959
{Text: "List a few popular cookie recipes."},
60-
}},
60+
},
61+
Role: "user"},
6162
}
6263
modelName := "gemini-2.0-flash-001"
6364

genai/count_tokens/counttoken_compute_with_txt.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func computeWithTxt(w io.Writer) error {
4040
contents := []*genai.Content{
4141
{Parts: []*genai.Part{
4242
{Text: "What's the longest word in the English language?"},
43-
}},
43+
},
44+
Role: "user"},
4445
}
4546

4647
resp, err := client.Models.ComputeTokens(ctx, modelName, contents, nil)

genai/count_tokens/counttoken_resp_with_txt.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func generateTextAndCount(w io.Writer) error {
4040
contents := []*genai.Content{
4141
{Parts: []*genai.Part{
4242
{Text: "Why is the sky blue?"},
43-
}},
43+
},
44+
Role: "user"},
4445
}
4546

4647
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)

genai/count_tokens/counttoken_with_txt_vid.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func countWithTxtAndVid(w io.Writer) error {
4343
FileURI: "gs://cloud-samples-data/generative-ai/video/pixel8.mp4",
4444
MIMEType: "video/mp4",
4545
}},
46-
}},
46+
},
47+
Role: "user"},
4748
}
4849

4950
resp, err := client.Models.CountTokens(ctx, modelName, contents, nil)

genai/text_generation/textgen_code_with_pdf.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func generateWithPDF(w io.Writer) error {
4343
FileURI: "https://storage.googleapis.com/cloud-samples-data/generative-ai/text/inefficient_fibonacci_series_python_code.pdf",
4444
MIMEType: "application/pdf",
4545
}},
46-
}},
46+
},
47+
Role: "user"},
4748
}
4849

4950
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)

genai/text_generation/textgen_transcript_with_gcs_audio.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Use speaker A, speaker B, etc. to identify speakers.`},
4444
FileURI: "gs://cloud-samples-data/generative-ai/audio/pixel.mp3",
4545
MIMEType: "audio/mpeg",
4646
}},
47-
}},
47+
},
48+
Role: "user"},
4849
}
4950

5051
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)

genai/text_generation/textgen_with_gcs_audio.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Create a chapter breakdown with timestamps for key sections or topics discussed.
4545
FileURI: "gs://cloud-samples-data/generative-ai/audio/pixel.mp3",
4646
MIMEType: "audio/mpeg",
4747
}},
48-
}},
48+
},
49+
Role: "user"},
4950
}
5051

5152
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)

genai/text_generation/textgen_with_mute_video.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func generateWithMuteVideo(w io.Writer) error {
4343
FileURI: "gs://cloud-samples-data/generative-ai/video/ad_copy_from_video.mp4",
4444
MIMEType: "video/mp4",
4545
}},
46-
}},
46+
},
47+
Role: "user"},
4748
}
4849

4950
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)

0 commit comments

Comments
 (0)