Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions go/genkit/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
10 changes: 8 additions & 2 deletions go/genkit/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
14 changes: 14 additions & 0 deletions go/samples/flow-sample1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"fmt"
"log"
"strconv"

"github.com/firebase/genkit/go/genkit"
)
Expand All @@ -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"`
}
Expand Down