mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 00:45:29 +08:00
40 lines
738 B
Go
40 lines
738 B
Go
package responses
|
|
|
|
import (
|
|
"strings"
|
|
|
|
openaifmt "ds2api/internal/format/openai"
|
|
)
|
|
|
|
type responsesDeltaBatch struct {
|
|
runtime *responsesStreamRuntime
|
|
kind string
|
|
text strings.Builder
|
|
}
|
|
|
|
func (b *responsesDeltaBatch) append(kind, text string) {
|
|
if text == "" {
|
|
return
|
|
}
|
|
if b.kind != "" && b.kind != kind {
|
|
b.flush()
|
|
}
|
|
b.kind = kind
|
|
b.text.WriteString(text)
|
|
}
|
|
|
|
func (b *responsesDeltaBatch) flush() {
|
|
if b.kind == "" || b.text.Len() == 0 {
|
|
return
|
|
}
|
|
text := b.text.String()
|
|
switch b.kind {
|
|
case "reasoning":
|
|
b.runtime.sendEvent("response.reasoning.delta", openaifmt.BuildResponsesReasoningDeltaPayload(b.runtime.responseID, text))
|
|
case "text":
|
|
b.runtime.emitTextDelta(text)
|
|
}
|
|
b.kind = ""
|
|
b.text.Reset()
|
|
}
|