Skip to content

Commit 76a4f70

Browse files
authored
fix(go/ai): fixed custom options schema and dynamic embedder input schema (#3538)
1 parent 6c6aba1 commit 76a4f70

File tree

9 files changed

+141
-217
lines changed

9 files changed

+141
-217
lines changed

go/ai/embedder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ func NewEmbedder(name string, opts *EmbedderOptions, fn EmbedderFunc) Embedder {
121121

122122
inputSchema := core.InferSchemaMap(EmbedRequest{})
123123
if inputSchema != nil && opts.ConfigSchema != nil {
124-
if _, ok := inputSchema["options"]; ok {
125-
inputSchema["options"] = opts.ConfigSchema
124+
if props, ok := inputSchema["properties"].(map[string]any); ok {
125+
props["options"] = opts.ConfigSchema
126126
}
127127
}
128128

129129
return &embedder{
130-
ActionDef: *core.NewAction(name, api.ActionTypeEmbedder, metadata, nil, fn),
130+
ActionDef: *core.NewAction(name, api.ActionTypeEmbedder, metadata, inputSchema, fn),
131131
}
132132
}
133133

go/ai/evaluator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ func NewEvaluator(name string, opts *EvaluatorOptions, fn EvaluatorFunc) Evaluat
184184

185185
inputSchema := core.InferSchemaMap(EvaluatorRequest{})
186186
if inputSchema != nil && opts.ConfigSchema != nil {
187-
if _, ok := inputSchema["options"]; ok {
188-
inputSchema["options"] = opts.ConfigSchema
187+
if props, ok := inputSchema["properties"].(map[string]any); ok {
188+
props["options"] = opts.ConfigSchema
189189
}
190190
}
191191

go/ai/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func NewModel(name string, opts *ModelOptions, fn ModelFunc) Model {
173173

174174
inputSchema := core.InferSchemaMap(ModelRequest{})
175175
if inputSchema != nil && opts.ConfigSchema != nil {
176-
if _, ok := inputSchema["config"]; ok {
177-
inputSchema["config"] = opts.ConfigSchema
176+
if props, ok := inputSchema["properties"].(map[string]any); ok {
177+
props["config"] = opts.ConfigSchema
178178
}
179179
}
180180

go/ai/retriever.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func NewRetriever(name string, opts *RetrieverOptions, fn RetrieverFunc) Retriev
115115

116116
inputSchema := core.InferSchemaMap(RetrieverRequest{})
117117
if inputSchema != nil && opts.ConfigSchema != nil {
118-
if _, ok := inputSchema["options"]; ok {
119-
inputSchema["options"] = opts.ConfigSchema
118+
if props, ok := inputSchema["properties"].(map[string]any); ok {
119+
props["options"] = opts.ConfigSchema
120120
}
121121
}
122122

go/internal/base/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func InferJSONSchema(x any) (s *jsonschema.Schema) {
9494
},
9595
}
9696
s = r.Reflect(x)
97-
// TODO: Unwind this change once Monaco Editor supports newer than JSON schema draft-07.
9897
s.Version = ""
98+
s.ID = ""
9999
return s
100100
}
101101

go/internal/base/json_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func TestSchemaAsMap(t *testing.T) {
7878
}
7979

8080
want := map[string]any{
81-
"$id": string("https://github.com/firebase/genkit/go/internal/base/foo"),
8281
"additionalProperties": bool(false),
8382
"properties": map[string]any{
8483
"BarField": map[string]any{

go/plugins/googlegenai/gemini.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ import (
4040
)
4141

4242
const (
43-
// Thinking budget limit
44-
thinkingBudgetMax = 24576
45-
4643
// Tool name regex
4744
toolNameRegex = "^[a-zA-Z_][a-zA-Z0-9_.-]{0,63}$"
4845
)
@@ -203,8 +200,8 @@ func newEmbedder(client *genai.Client, name string, embedOpts *ai.EmbedderOption
203200
var content []*genai.Content
204201
var embedConfig *genai.EmbedContentConfig
205202

206-
if options, _ := req.Options.(*genai.EmbedContentConfig); options != nil {
207-
embedConfig = options
203+
if config, ok := req.Options.(*genai.EmbedContentConfig); ok {
204+
embedConfig = config
208205
}
209206

210207
for _, doc := range req.Input {

0 commit comments

Comments
 (0)