MCPcopy Create free account
hub / github.com/cloudwego/eino-examples / ExampleOfMessageParserLambda

Function ExampleOfMessageParserLambda

components/lambda/lambda.go:127–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125}
126
127func ExampleOfMessageParserLambda() {
128 // 创建解析器
129 parser := schema.NewMessageJSONParser[*MyStruct](&schema.MessageJSONParseConfig{
130 ParseFrom: schema.MessageParseFromContent,
131 ParseKeyPath: "", // 如果仅需要 parse 子字段,可用 "key.sub.grandsub"
132 })
133
134 // 创建解析 Lambda
135 parserLambda := compose.MessageParser(parser)
136
137 // 在 Chain 中使用
138 chain := compose.NewChain[*schema.Message, *MyStruct]()
139 chain.AppendLambda(parserLambda)
140
141 // 使用示例
142 runner, _ := chain.Compile(context.Background())
143 parsed, _ := runner.Invoke(context.Background(), &schema.Message{
144 Content: `{"id": 1}`,
145 })
146 // parsed.ID == 1
147
148 _ = parsed
149}

Callers

nothing calls this directly

Calls 2

CompileMethod · 0.65
InvokeMethod · 0.45

Tested by

no test coverage detected