diff --git a/go/genkit/action.go b/go/genkit/action.go index f9c1774e0f..63e466c338 100644 --- a/go/genkit/action.go +++ b/go/genkit/action.go @@ -196,10 +196,11 @@ func (a *Action[I, O, S]) desc() actionDesc { } // Required by genkit UI: if ad.Metadata == nil { - ad.Metadata = map[string]any{} + ad.Metadata = map[string]any{ + "inputSchema": nil, + "outputSchema": nil, + } } - ad.Metadata["inputSchema"] = nil - ad.Metadata["outputSchema"] = nil return ad } @@ -215,5 +216,8 @@ func inferJSONSchema(x any) (s *jsonschema.Schema) { // instead of nested inside a "$defs" object. r.ExpandedStruct = true } - return r.Reflect(x) + s = r.Reflect(x) + // TODO: Unwind this change once Monaco Editor supports newer than JSON schema draft-07. + s.Version = "" + return s } diff --git a/go/genkit/flow.go b/go/genkit/flow.go index 86c3304248..8a19a5d855 100644 --- a/go/genkit/flow.go +++ b/go/genkit/flow.go @@ -239,8 +239,14 @@ type FlowResult[O any] struct { // action creates an action for the flow. See the comment at the top of this file for more information. func (f *Flow[I, O, S]) action() *Action[*flowInstruction[I], *flowState[I, O], S] { - return NewStreamingAction(f.name, nil, func(ctx context.Context, inst *flowInstruction[I], cb StreamingCallback[S]) (*flowState[I, O], error) { - tracing.SpanMetaKey.FromContext(ctx).SetAttr("flow:wrapperAction", "true") + var i I + var o O + metadata := map[string]any{ + "inputSchema": inferJSONSchema(i), + "outputSchema": inferJSONSchema(o), + } + return NewStreamingAction(f.name, metadata, func(ctx context.Context, inst *flowInstruction[I], cb StreamingCallback[S]) (*flowState[I, O], error) { + spanMetaKey.fromContext(ctx).SetAttr("flow:wrapperAction", "true") return f.runInstruction(ctx, inst, cb) }) } diff --git a/go/samples/flow-sample1/main.go b/go/samples/flow-sample1/main.go index 4d00d3e40c..215d10130a 100644 --- a/go/samples/flow-sample1/main.go +++ b/go/samples/flow-sample1/main.go @@ -26,6 +26,7 @@ import ( "context" "fmt" "log" + "strconv" "github.com/firebase/genkit/go/genkit" ) @@ -43,6 +44,19 @@ func main() { return genkit.RunFlow(ctx, basic, "foo") }) + type complex struct { + Key string `json:"key"` + Value int `json:"value"` + } + + genkit.DefineFlow("complex", func(ctx context.Context, c complex, _ genkit.NoStream) (string, error) { + foo, err := genkit.Run(ctx, "call-llm", func() (string, error) { return c.Key + ": " + strconv.Itoa(c.Value), nil }) + if err != nil { + return "", err + } + return foo, nil + }) + type chunk struct { Count int `json:"count"` }