mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 17:05:32 +08:00
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package assistantturn
|
|
|
|
import (
|
|
"ds2api/internal/httpapi/openai/shared"
|
|
"ds2api/internal/sse"
|
|
)
|
|
|
|
type StreamEventType string
|
|
|
|
const (
|
|
StreamEventTextDelta StreamEventType = "text_delta"
|
|
StreamEventThinkingDelta StreamEventType = "thinking_delta"
|
|
StreamEventToolCall StreamEventType = "tool_call"
|
|
StreamEventDone StreamEventType = "done"
|
|
StreamEventError StreamEventType = "error"
|
|
StreamEventPing StreamEventType = "ping"
|
|
)
|
|
|
|
type StreamEvent struct {
|
|
Type StreamEventType
|
|
Text string
|
|
Thinking string
|
|
ToolCall any
|
|
Error *OutputError
|
|
Usage *Usage
|
|
}
|
|
|
|
type Accumulator struct {
|
|
inner shared.StreamAccumulator
|
|
}
|
|
|
|
type AccumulatorOptions struct {
|
|
ThinkingEnabled bool
|
|
SearchEnabled bool
|
|
StripReferenceMarkers bool
|
|
}
|
|
|
|
func NewAccumulator(opts AccumulatorOptions) *Accumulator {
|
|
return &Accumulator{
|
|
inner: shared.StreamAccumulator{
|
|
ThinkingEnabled: opts.ThinkingEnabled,
|
|
SearchEnabled: opts.SearchEnabled,
|
|
StripReferenceMarkers: opts.StripReferenceMarkers,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (a *Accumulator) Apply(parsed sse.LineResult) shared.StreamAccumulatorResult {
|
|
if a == nil {
|
|
return shared.StreamAccumulatorResult{}
|
|
}
|
|
return a.inner.Apply(parsed)
|
|
}
|
|
|
|
func (a *Accumulator) Snapshot() (rawText, text, rawThinking, thinking, detectionThinking string) {
|
|
if a == nil {
|
|
return "", "", "", "", ""
|
|
}
|
|
return a.inner.RawText.String(),
|
|
a.inner.Text.String(),
|
|
a.inner.RawThinking.String(),
|
|
a.inner.Thinking.String(),
|
|
a.inner.ToolDetectionThinking.String()
|
|
}
|