feat(devops): add an example of map[string]any (#78)

drew/english
liujian-bytedance 11 months ago committed by GitHub
parent a021f26cb8
commit fb3070ab6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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)
}

@ -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)

Loading…
Cancel
Save