Skip to content

Commit f696bfb

Browse files
committed
update imagen model config
1 parent 7aa0ed2 commit f696bfb

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

go/plugins/googlegenai/gemini.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,27 @@ func configToMap(config any) map[string]any {
8888
r := jsonschema.Reflector{
8989
DoNotReference: true, // Prevent $ref usage
9090
ExpandedStruct: true, // Include all fields directly
91-
// Prevent stack overflow panic due type traversal recursion (circular references)
92-
// [genai.Schema] should not be used at this point since Schema is provided later
9391
// NOTE: keep track of updated fields in [genai.GenerateContentConfig] since
9492
// they could create runtime panics when parsing fields with type recursion
95-
IgnoredTypes: []any{genai.Schema{}},
93+
IgnoredTypes: []any{
94+
genai.Schema{},
95+
genai.Tool{},
96+
genai.ToolConfig{},
97+
genai.HTTPOptions{},
98+
},
9699
}
100+
97101
schema := r.Reflect(config)
98102
result := base.SchemaAsMap(schema)
103+
104+
// prevent users to override Genkit primitive features
105+
if propertiesMap, ok := result["properties"].(map[string]any); ok {
106+
delete(propertiesMap, "cachedContent")
107+
delete(propertiesMap, "systemInstruction")
108+
delete(propertiesMap, "responseMimeType")
109+
delete(propertiesMap, "responseJsonSchema")
110+
delete(propertiesMap, "candidateCount")
111+
}
99112
return result
100113
}
101114

@@ -140,9 +153,8 @@ func newModel(client *genai.Client, name string, opts ai.ModelOptions) ai.Model
140153

141154
var config any
142155
config = &genai.GenerateContentConfig{}
143-
if imageOpts, found := supportedImagenModels[name]; found {
156+
if strings.Contains(name, "imagen") {
144157
config = &genai.GenerateImagesConfig{}
145-
opts = imageOpts
146158
}
147159
meta := &ai.ModelOptions{
148160
Label: opts.Label,

go/plugins/googlegenai/googlegenai.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (ga *GoogleAI) ListActions(ctx context.Context) []core.ActionDesc {
346346
"model": map[string]any{
347347
"supports": map[string]any{
348348
"media": true,
349-
"multiturn": false,
349+
"multiturn": true,
350350
"systemRole": false,
351351
"tools": false,
352352
"toolChoice": false,

go/plugins/googlegenai/models.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ type genaiModels struct {
406406
func listGenaiModels(ctx context.Context, client *genai.Client) (genaiModels, error) {
407407
models := genaiModels{}
408408
allowedModels := []string{"gemini", "gemma"}
409-
allowedImagenModels := []string{"imagen"}
410409

411410
for item, err := range client.Models.All(ctx) {
412411
var name string
@@ -428,26 +427,20 @@ func listGenaiModels(ctx context.Context, client *genai.Client) (genaiModels, er
428427
continue
429428
}
430429

431-
if !slices.Contains(item.SupportedActions, "generateContent") {
432-
continue
433-
}
434-
435-
found := slices.ContainsFunc(allowedModels, func(s string) bool {
436-
return strings.Contains(name, s)
437-
})
438-
// filter out: Aqa, Text-bison, Chat, learnlm
439-
if found {
440-
models.gemini = append(models.gemini, name)
430+
if slices.Contains(item.SupportedActions, "predict") && strings.Contains(name, "imagen") {
431+
models.imagen = append(models.imagen, name)
441432
continue
442433
}
443434

444-
found = slices.ContainsFunc(allowedImagenModels, func(s string) bool {
445-
return strings.Contains(name, s)
446-
})
447-
// filter out: Aqa, Text-bison, Chat, learnlm
448-
if found {
449-
models.imagen = append(models.imagen, name)
450-
continue
435+
if slices.Contains(item.SupportedActions, "generateContent") {
436+
found := slices.ContainsFunc(allowedModels, func(s string) bool {
437+
return strings.Contains(name, s)
438+
})
439+
// filter out: Aqa, Text-bison, Chat, learnlm
440+
if found {
441+
models.gemini = append(models.gemini, name)
442+
continue
443+
}
451444
}
452445
}
453446

0 commit comments

Comments
 (0)