Skip to content

Commit e6893e6

Browse files
committed
feat(genai): Add generate content with routing option
1 parent 82ce846 commit e6893e6

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

genai/content_cache/contentcache_update.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ func updateContentCache(w io.Writer, cacheName string) error {
3838

3939
// Update expire time using TTL
4040
resp, err := client.Caches.Update(ctx, cacheName, &genai.UpdateCachedContentConfig{
41-
TTL: "36000s",
41+
TTL: int64(36000),
4242
})
4343
if err != nil {
4444
return fmt.Errorf("failed to update content cache exp. time with TTL: %w", err)
4545
}
4646

47-
fmt.Fprintf(w, "Cache expires in: %s\n", time.Until(*resp.ExpireTime))
47+
fmt.Fprintf(w, "Cache expires in: %s\n", time.Until(resp.ExpireTime))
4848
// Example response:
4949
// Cache expires in: 10h0m0.005875s
5050

5151
// Update expire time using specific time stamp
5252
inSevenDays := time.Now().Add(7 * 24 * time.Hour)
5353
resp, err = client.Caches.Update(ctx, cacheName, &genai.UpdateCachedContentConfig{
54-
ExpireTime: &inSevenDays,
54+
ExpireTime: inSevenDays,
5555
})
5656
if err != nil {
5757
return fmt.Errorf("failed to update content cache expire time: %w", err)
5858
}
5959

60-
fmt.Fprintf(w, "Cache expires in: %s\n", time.Until(*resp.ExpireTime))
60+
fmt.Fprintf(w, "Cache expires in: %s\n", time.Until(resp.ExpireTime))
6161
// Example response:
6262
// Cache expires in: 167h59m59.80327s
6363

genai/content_cache/contentcache_use_with_txt.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ func useContentCacheWithTxt(w io.Writer, cacheName string) error {
4646
return fmt.Errorf("failed to use content cache to generate content: %w", err)
4747
}
4848

49-
respText, err := resp.Text()
50-
if err != nil {
51-
return fmt.Errorf("failed to convert model response to text: %w", err)
52-
}
49+
respText := resp.Text()
50+
5351
fmt.Fprintln(w, respText)
5452

5553
// Example response:

genai/controlled_generation/ctrlgen_with_enum_schema.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ func generateWithEnumSchema(w io.Writer) error {
5454
return fmt.Errorf("failed to generate content: %w", err)
5555
}
5656

57-
respText, err := resp.Text()
58-
if err != nil {
59-
return fmt.Errorf("failed to convert model response to text: %w", err)
60-
}
57+
respText := resp.Text()
58+
6159
fmt.Fprintln(w, respText)
6260

6361
// Example response:

genai/controlled_generation/ctrlgen_with_nullable_schema.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ Finally, Saturday rounds off the week with sunny skies, a temperature of 80°F,
6363
Items: &genai.Schema{
6464
Type: "object",
6565
Properties: map[string]*genai.Schema{
66-
"Day": {Type: "string", Nullable: true},
67-
"Forecast": {Type: "string", Nullable: true},
68-
"Temperature": {Type: "integer", Nullable: true},
69-
"Humidity": {Type: "string", Nullable: true},
70-
"Wind Speed": {Type: "integer", Nullable: true},
66+
"Day": {Type: "string", Nullable: genai.Ptr(true)},
67+
"Forecast": {Type: "string", Nullable: genai.Ptr(true)},
68+
"Temperature": {Type: "integer", Nullable: genai.Ptr(true)},
69+
"Humidity": {Type: "string", Nullable: genai.Ptr(true)},
70+
"Wind Speed": {Type: "integer", Nullable: genai.Ptr(true)},
7171
},
7272
Required: []string{"Day", "Temperature", "Forecast", "Wind Speed"},
7373
},
@@ -81,10 +81,8 @@ Finally, Saturday rounds off the week with sunny skies, a temperature of 80°F,
8181
return fmt.Errorf("failed to generate content: %w", err)
8282
}
8383

84-
respText, err := resp.Text()
85-
if err != nil {
86-
return fmt.Errorf("failed to convert model response to text: %w", err)
87-
}
84+
respText := resp.Text()
85+
8886
fmt.Fprintln(w, respText)
8987

9088
// Example response:

genai/controlled_generation/ctrlgen_with_resp_schema.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ func generateWithRespSchema(w io.Writer) error {
6666
return fmt.Errorf("failed to generate content: %w", err)
6767
}
6868

69-
respText, err := resp.Text()
70-
if err != nil {
71-
return fmt.Errorf("failed to convert model response to text: %w", err)
72-
}
69+
respText := resp.Text()
70+
7371
fmt.Fprintln(w, respText)
7472

7573
// Example response:

0 commit comments

Comments
 (0)