mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 00:15:28 +08:00
Previously retry/continue requests reused the initial PoW header and lacked parent_message_id, causing them to land as disconnected root messages in the DeepSeek session instead of proper follow-up turns. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package sse
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// LineResult is the normalized parse result for one DeepSeek SSE line.
|
|
type LineResult struct {
|
|
Parsed bool
|
|
Stop bool
|
|
ContentFilter bool
|
|
ErrorMessage string
|
|
Parts []ContentPart
|
|
ToolDetectionThinkingParts []ContentPart
|
|
NextType string
|
|
ResponseMessageID int
|
|
}
|
|
|
|
// ParseDeepSeekContentLine centralizes one-line DeepSeek SSE parsing for both
|
|
// streaming and non-streaming handlers.
|
|
func ParseDeepSeekContentLine(raw []byte, thinkingEnabled bool, currentType string) LineResult {
|
|
chunk, done, parsed := ParseDeepSeekSSELine(raw)
|
|
if !parsed {
|
|
return LineResult{NextType: currentType}
|
|
}
|
|
if done {
|
|
return LineResult{Parsed: true, Stop: true, NextType: currentType}
|
|
}
|
|
if errObj, hasErr := chunk["error"]; hasErr {
|
|
return LineResult{
|
|
Parsed: true,
|
|
Stop: true,
|
|
ErrorMessage: fmt.Sprintf("%v", errObj),
|
|
NextType: currentType,
|
|
}
|
|
}
|
|
if code, _ := chunk["code"].(string); code == "content_filter" {
|
|
return LineResult{
|
|
Parsed: true,
|
|
Stop: true,
|
|
ContentFilter: true,
|
|
NextType: currentType,
|
|
}
|
|
}
|
|
if hasContentFilterStatus(chunk) {
|
|
return LineResult{
|
|
Parsed: true,
|
|
Stop: true,
|
|
ContentFilter: true,
|
|
NextType: currentType,
|
|
}
|
|
}
|
|
parts, detectionThinkingParts, finished, nextType := ParseSSEChunkForContentDetailed(chunk, thinkingEnabled, currentType)
|
|
parts = filterLeakedContentFilterParts(parts)
|
|
detectionThinkingParts = filterLeakedContentFilterParts(detectionThinkingParts)
|
|
var respMsgID int
|
|
observeResponseMessageID(chunk, &respMsgID)
|
|
return LineResult{
|
|
Parsed: true,
|
|
Stop: finished,
|
|
Parts: parts,
|
|
ToolDetectionThinkingParts: detectionThinkingParts,
|
|
NextType: nextType,
|
|
ResponseMessageID: respMsgID,
|
|
}
|
|
}
|