diff --git a/devops/debug/graph/graph.go b/devops/debug/graph/graph.go index fbaf2eb..8c5e198 100644 --- a/devops/debug/graph/graph.go +++ b/devops/debug/graph/graph.go @@ -18,7 +18,6 @@ package graph import ( "context" - "github.com/cloudwego/eino/compose" "github.com/cloudwego/eino-examples/internal/logs" @@ -61,3 +60,51 @@ func RegisterSimpleGraph(ctx context.Context) { logs.Infof("eino simple graph output is: %v", message) } + +type NodeInfo struct { + Message string +} + +func RegisterGraphOfInterfaceType(ctx context.Context) { + g := compose.NewGraph[any, string]() + + _ = g.AddLambdaNode("node_1", compose.InvokableLambda(func(ctx context.Context, input *NodeInfo) (output string, err error) { + if input == nil { + return "", nil + } + return input.Message + " process by node_1,", 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.AddLambdaNode("node_3", compose.InvokableLambda(func(ctx context.Context, input string) (output string, err error) { + return input + " process by node_3,", nil + })) + + _ = g.AddEdge(compose.START, "node_1") + + _ = g.AddEdge("node_1", "node_2") + + _ = g.AddEdge("node_2", "node_3") + + _ = g.AddEdge("node_3", compose.END) + + r, err := g.Compile(ctx) + if err != nil { + logs.Errorf("compile graph failed, err=%v", err) + return + } + + message, err := r.Invoke(ctx, &NodeInfo{ + Message: "test data", + }) + + if err != nil { + logs.Errorf("invoke graph failed, err=%v", err) + return + } + + logs.Infof("eino simple graph output is: %v", message) +} diff --git a/devops/debug/main.go b/devops/debug/main.go index 8b32bbf..220d2a6 100644 --- a/devops/debug/main.go +++ b/devops/debug/main.go @@ -32,8 +32,7 @@ import ( func main() { ctx := context.Background() - // Init eino devops server - err := devops.Init(ctx) + err := devops.Init(ctx, devops.AppendType(&graph.NodeInfo{})) if err != nil { logs.Errorf("[eino dev] init failed, err=%v", err) return @@ -44,6 +43,8 @@ func main() { graph.RegisterSimpleGraph(ctx) graph.RegisterSimpleStateGraph(ctx) + graph.RegisterGraphOfInterfaceType(ctx) + // Blocking process exits sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) diff --git a/go.mod b/go.mod index 4d15bad..92d9d44 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250114173536-ca9322ed9f9a github.com/cloudwego/eino-ext/components/retriever/volc_vikingdb v0.0.0-20250108030439-1493aa120cb1 github.com/cloudwego/eino-ext/components/tool/duckduckgo v0.0.0-20250116120445-4165a5358a34 - github.com/cloudwego/eino-ext/devops v0.0.0-20250116071241-3f1eaaafd49c + github.com/cloudwego/eino-ext/devops v0.0.0-20250120131302-5fded775a2a2 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/getkin/kin-openapi v0.118.0 github.com/ollama/ollama v0.3.0 diff --git a/go.sum b/go.sum index 59f19ef..a8187d7 100644 --- a/go.sum +++ b/go.sum @@ -108,8 +108,8 @@ github.com/cloudwego/eino-ext/components/retriever/volc_vikingdb v0.0.0-20250108 github.com/cloudwego/eino-ext/components/retriever/volc_vikingdb v0.0.0-20250108030439-1493aa120cb1/go.mod h1:lj6h0MYtiEGwWDVdkOd4VmZBF7JVWV5bNxv0/r2C+W0= github.com/cloudwego/eino-ext/components/tool/duckduckgo v0.0.0-20250116120445-4165a5358a34 h1:uiAF49aHUfOW3hT8dJzrrrCt7dTqoSlUynp18C5QKPU= github.com/cloudwego/eino-ext/components/tool/duckduckgo v0.0.0-20250116120445-4165a5358a34/go.mod h1:Do8C+KMH+3PiF/jYV/8oFQz+UvCTrThswB9fZWiqfgI= -github.com/cloudwego/eino-ext/devops v0.0.0-20250116071241-3f1eaaafd49c h1:WslgauCA6SisgAPn7cNlhHrmJsX5Fq/tG+87oYCTH3s= -github.com/cloudwego/eino-ext/devops v0.0.0-20250116071241-3f1eaaafd49c/go.mod h1:MzPGghc4J7rSevtxeZpqAejpaFbkoCNzG6AQLG93WmE= +github.com/cloudwego/eino-ext/devops v0.0.0-20250120131302-5fded775a2a2 h1:qAfETnvohhxHt+E1f9KCz7l4tcZGmLuJyEIGhBpO42w= +github.com/cloudwego/eino-ext/devops v0.0.0-20250120131302-5fded775a2a2/go.mod h1:++GgqYXdxPJYxbXzK/613wxaK7Blg3XlqZU/gH8CPXU= github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250114173020-562b40c138d3 h1:DHeeScM7IOmh8YxbLLNu5FrUMuylDfnsuZ3QLTEThq0= github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250114173020-562b40c138d3/go.mod h1:H5UK9sjotuBaZCO6CFvPRaYDBBfRz/MSFR9ZNEmwgCo= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=