Files
CamTalk/backend/internal/eino/state.go
cfy666 4b731b5ac0 feat: 实现 Eino Graph 构建与 Orchestrator 适配器,切换 main.go
- graph.go: 构建 Graph 拓扑 START→STT→History→ChatModel→Splitter→TTS→Done→END
  - 创建 eino-ext ChatModel 对接 DashScope OpenAI 兼容接口
  - 统一使用值类型(PipelineInput/PipelineOutput)
  - Callback 在运行时通过 Stream option 传入
- adapter.go: EinoOrchestrator 实现 orchestrator.Orchestrator 接口
  - 解码 base64 音频/图片,注入 context 值
  - 调用 Graph.Stream() 触发惰性执行并消费输出
  - 追加用户/助手消息到历史
- main.go: 移除旧 llmService + orchestrator.New()
  替换为 eino.NewPipelineGraph() + eino.NewEinoOrchestrator()
- 各节点统一使用值类型,State 传递请求元数据

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-19 21:58:17 +08:00

46 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package eino
import (
"context"
"strings"
"sync"
)
// PipelineState Graph 全局状态,用于跨节点收集数据。
// 通过 compose.WithGenLocalState 注册,各节点通过 compose.ProcessState 读写。
type PipelineState struct {
mu sync.Mutex
FullResponse strings.Builder // LLM 完整回复(由 Callback 累积)
TranscribedText string // STT 识别文本
Model string // 实际使用的模型名
TokenUsage *TokenUsage // token 用量
// 从 PipelineInput 复制的元数据供下游节点History、Done读取
SessionID string
RequestID string
ImageData []byte
Scenario string
DetailLevel string
Language string
TTSEnabled bool
}
// genLocalState 创建每请求的 PipelineState 实例。
func genLocalState(ctx context.Context) *PipelineState {
return &PipelineState{}
}
// AppendText 追加文本到 FullResponse线程安全
func (s *PipelineState) AppendText(text string) {
s.mu.Lock()
defer s.mu.Unlock()
s.FullResponse.WriteString(text)
}
// GetFullResponse 获取完整回复文本(线程安全)。
func (s *PipelineState) GetFullResponse() string {
s.mu.Lock()
defer s.mu.Unlock()
return s.FullResponse.String()
}