2026-06-19 21:49:28 +08:00
|
|
|
|
package eino
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
"sync"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// PipelineState Graph 全局状态,用于跨节点收集数据。
|
2026-06-19 21:58:17 +08:00
|
|
|
|
// 通过 compose.WithGenLocalState 注册,各节点通过 compose.ProcessState 读写。
|
2026-06-19 21:49:28 +08:00
|
|
|
|
type PipelineState struct {
|
|
|
|
|
|
mu sync.Mutex
|
|
|
|
|
|
FullResponse strings.Builder // LLM 完整回复(由 Callback 累积)
|
|
|
|
|
|
TranscribedText string // STT 识别文本
|
|
|
|
|
|
Model string // 实际使用的模型名
|
|
|
|
|
|
TokenUsage *TokenUsage // token 用量
|
2026-06-19 21:58:17 +08:00
|
|
|
|
|
|
|
|
|
|
// 从 PipelineInput 复制的元数据,供下游节点(History、Done)读取
|
|
|
|
|
|
SessionID string
|
|
|
|
|
|
RequestID string
|
|
|
|
|
|
ImageData []byte
|
|
|
|
|
|
Scenario string
|
|
|
|
|
|
DetailLevel string
|
|
|
|
|
|
Language string
|
|
|
|
|
|
TTSEnabled bool
|
2026-06-19 21:49:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
|
}
|