From fb3070ab6e2b286240155a53ea253641ced25665 Mon Sep 17 00:00:00 2001 From: liujian-bytedance Date: Fri, 13 Jun 2025 10:52:02 +0800 Subject: [PATCH] feat(devops): add an example of map[string]any (#78) --- devops/debug/graph/graph.go | 56 +++++++++++++++++++++++++++++++++++++ devops/debug/main.go | 1 + 2 files changed, 57 insertions(+) diff --git a/devops/debug/graph/graph.go b/devops/debug/graph/graph.go index c9a91fc..6c54be7 100644 --- a/devops/debug/graph/graph.go +++ b/devops/debug/graph/graph.go @@ -18,6 +18,7 @@ package graph import ( "context" + "fmt" "github.com/cloudwego/eino/compose" @@ -68,3 +69,58 @@ func RegisterSimpleGraph(ctx context.Context) { logs.Infof("eino simple graph output is: %v", message) } + +// When using eino debugging plugin, in the input box, you need to specify the concrete type of 'any' in map[string]any. For example, you can input the following data for debugging: +//{ +// "name": { +// "_value": "alice", +// "_eino_go_type": "string" +// }, +// "score": { +// "_value": "99", +// "_eino_go_type": "int" +// } +//} + +func RegisterAnyInputGraph(ctx context.Context) { + g := compose.NewGraph[map[string]any, string]() + + _ = g.AddLambdaNode("node_1", compose.InvokableLambda(func(ctx context.Context, input map[string]any) (output string, err error) { + for k, v := range input { + switch v.(type) { + case string: + output += k + ":" + v.(string) + "," + case int: + output += k + ":" + fmt.Sprintf("%d", v.(int)) + default: + return "", fmt.Errorf("unsupported type: %T", v) + } + } + + return output, nil + })) + + _ = g.AddLambdaNode("node_2", compose.InvokableLambda(func(ctx context.Context, input string) (output string, err error) { + return input + " process by node_2,", nil + })) + + _ = g.AddEdge(compose.START, "node_1") + + _ = g.AddEdge("node_1", "node_2") + + _ = g.AddEdge("node_2", compose.END) + + r, err := g.Compile(ctx) + if err != nil { + logs.Errorf("compile graph failed, err=%v", err) + return + } + + message, err := r.Invoke(ctx, map[string]any{"name": "bob", "score": 100}) + if err != nil { + logs.Errorf("invoke graph failed, err=%v", err) + return + } + + logs.Infof("eino any input graph output is: %v", message) +} diff --git a/devops/debug/main.go b/devops/debug/main.go index 8b32bbf..90458fd 100644 --- a/devops/debug/main.go +++ b/devops/debug/main.go @@ -43,6 +43,7 @@ func main() { chain.RegisterSimpleChain(ctx) graph.RegisterSimpleGraph(ctx) graph.RegisterSimpleStateGraph(ctx) + graph.RegisterAnyInputGraph(ctx) // Blocking process exits sigs := make(chan os.Signal, 1)