f3abc5fdc6
Deploy Slides / build-and-deploy (push) Successful in 1m39s
- eino-deep-dive.md: split slide 2 into code-only + explanation+SVG slides - async-deep-dive.md: split slide 2 into code-only + progress+SVG slides - harness.md: split slide 2 (4 Items + SVG) into two slides (2 Items each) - request-journey.md: split into middleware/handler + pipeline/finalization slides The frankfurt theme header (~40px) overlaps ~7px into the content zone, leaving ~467px effective height. Dense slides with code+Items+images exceeded this budget and were hidden behind the bars.
85 lines
2.2 KiB
Markdown
85 lines
2.2 KiB
Markdown
# Eino Graph 深入 — 构建与编排
|
|
|
|
有向图构建与本地状态管理
|
|
|
|
<div class="grid grid-cols-2 gap-4 mt-2">
|
|
|
|
<div>
|
|
|
|
```go {1-5|7-11|all}
|
|
g := compose.NewGraph[PipelineInput, PipelineOutput](
|
|
compose.WithGenLocalState(func(ctx context.Context) *PipelineState {
|
|
return &PipelineState{} // 每次调用获得全新状态
|
|
}),
|
|
)
|
|
|
|
g.AddLambdaNode(nodePromptOptimizer, &compose.Lambda{
|
|
StatePreHandler: preparePromptInput, // 从 state 读取输入
|
|
StatePostHandler: storePromptOutput, // 结果写回 state
|
|
})
|
|
```
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-col justify-center">
|
|
|
|
<v-clicks>
|
|
|
|
<Item title="WithGenLocalState — 隔离的执行上下文">
|
|
每次 `graph.Invoke()` 调用生成独立的 `PipelineState`,避免并发调用间的状态污染。State 在节点间通过 Pre/Post Handler 流转。
|
|
</Item>
|
|
|
|
<Item title="StatePreHandler / StatePostHandler 模式">
|
|
PreHandler 从全局 State 提取当前节点所需字段;PostHandler 将节点输出写回 State。节点本身无状态,所有数据经 State 中转。
|
|
</Item>
|
|
|
|
</v-clicks>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
---
|
|
|
|
# Eino Graph 深入 — 分支路由与重试
|
|
|
|
QualitySupervisor 驱动的条件分支
|
|
|
|
```go {1-10|all}
|
|
g.AddBranch(nodeQualitySupervisor, compose.NewGraphBranch(
|
|
func(ctx context.Context, _ PipelineInput) (string, error) {
|
|
var next string
|
|
_ = compose.ProcessState[*PipelineState](ctx,
|
|
func(_ context.Context, state *PipelineState) error {
|
|
next = state.NextNode // 质检结果决定路由
|
|
return nil
|
|
})
|
|
return next, nil
|
|
},
|
|
map[string]bool{
|
|
nodePromptOptimizer: true,
|
|
nodeFormatAdapter: true,
|
|
},
|
|
))
|
|
```
|
|
|
|
---
|
|
|
|
# 分支路由 — 逻辑与全貌
|
|
|
|
<v-clicks>
|
|
|
|
<Item title="路由逻辑">
|
|
质检通过 → FormatAdapter 直接输出;不通过且 retry < 3 → PromptOptimizer 重新优化;不通过且 retry >= 3 → FormatAdapter 降级输出。
|
|
</Item>
|
|
|
|
<Item title="管线全貌">
|
|
下图展示了完整的分支路由与重试机制,包括状态流转和降级路径。
|
|
</Item>
|
|
|
|
</v-clicks>
|
|
|
|
<div class="flex justify-center mt-2">
|
|
<img src="../public/pipeline-detail.svg" class="w-full max-h-[200px] object-contain" />
|
|
</div>
|