fix(sse): trim stream output from CONTENT_FILTER onward

This commit is contained in:
CJACK.
2026-03-31 01:26:43 +08:00
parent efebe9ebad
commit 3b60e3c8f9
4 changed files with 67 additions and 12 deletions

View File

@@ -22,7 +22,8 @@ func stripLeakedContentFilterSuffix(text string) string {
if text == "" {
return text
}
idx := strings.Index(strings.ToUpper(text), "CONTENT_FILTER")
upperText := strings.ToUpper(text)
idx := strings.Index(upperText, "CONTENT_FILTER")
if idx < 0 {
return text
}

View File

@@ -55,3 +55,13 @@ func TestParseDeepSeekContentLineDropsPureLeakedContentFilterChunk(t *testing.T)
t.Fatalf("expected empty parts, got %#v", res.Parts)
}
}
func TestParseDeepSeekContentLineTrimsFromContentFilterKeyword(t *testing.T) {
res := ParseDeepSeekContentLine([]byte(`data: {"p":"response/content","v":"模型会在命中 CONTENT_FILTER 时返回拒绝原因。"}`), false, "text")
if !res.Parsed || res.Stop {
t.Fatalf("expected parsed non-stop result: %#v", res)
}
if len(res.Parts) != 1 || res.Parts[0].Text != "模型会在命中" {
t.Fatalf("unexpected parts after filter: %#v", res.Parts)
}
}