mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-23 10:57:44 +08:00
修复吞字问题
This commit is contained in:
@@ -88,6 +88,71 @@ func TestParseSSEChunkForContentAfterAppendUsesUpdatedType(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSSEChunkForContentThinkingDisabledKeepsHiddenFragmentState(t *testing.T) {
|
||||
chunk1 := map[string]any{
|
||||
"p": "response/fragments",
|
||||
"o": "APPEND",
|
||||
"v": []any{
|
||||
map[string]any{"type": "THINK", "content": "我们"},
|
||||
},
|
||||
}
|
||||
parts1, finished1, nextType1 := ParseSSEChunkForContent(chunk1, false, "text")
|
||||
if finished1 {
|
||||
t.Fatal("expected first chunk unfinished")
|
||||
}
|
||||
if nextType1 != "thinking" {
|
||||
t.Fatalf("expected hidden THINK fragment to keep next type thinking, got %q", nextType1)
|
||||
}
|
||||
if len(parts1) != 0 {
|
||||
t.Fatalf("expected hidden thinking to be dropped, got %#v", parts1)
|
||||
}
|
||||
|
||||
chunk2 := map[string]any{
|
||||
"p": "response/fragments/-1/content",
|
||||
"v": "被",
|
||||
}
|
||||
parts2, finished2, nextType2 := ParseSSEChunkForContent(chunk2, false, nextType1)
|
||||
if finished2 {
|
||||
t.Fatal("expected second chunk unfinished")
|
||||
}
|
||||
if nextType2 != "thinking" {
|
||||
t.Fatalf("expected hidden continuation to keep next type thinking, got %q", nextType2)
|
||||
}
|
||||
if len(parts2) != 0 {
|
||||
t.Fatalf("expected hidden continuation to be dropped, got %#v", parts2)
|
||||
}
|
||||
|
||||
chunk3 := map[string]any{"v": "要求"}
|
||||
parts3, finished3, nextType3 := ParseSSEChunkForContent(chunk3, false, nextType2)
|
||||
if finished3 {
|
||||
t.Fatal("expected third chunk unfinished")
|
||||
}
|
||||
if nextType3 != "thinking" {
|
||||
t.Fatalf("expected pathless hidden continuation to keep next type thinking, got %q", nextType3)
|
||||
}
|
||||
if len(parts3) != 0 {
|
||||
t.Fatalf("expected pathless hidden continuation to be dropped, got %#v", parts3)
|
||||
}
|
||||
|
||||
chunk4 := map[string]any{
|
||||
"p": "response/fragments",
|
||||
"o": "APPEND",
|
||||
"v": []any{
|
||||
map[string]any{"type": "RESPONSE", "content": "答"},
|
||||
},
|
||||
}
|
||||
parts4, finished4, nextType4 := ParseSSEChunkForContent(chunk4, false, nextType3)
|
||||
if finished4 {
|
||||
t.Fatal("expected fourth chunk unfinished")
|
||||
}
|
||||
if nextType4 != "text" {
|
||||
t.Fatalf("expected RESPONSE fragment to switch next type text, got %q", nextType4)
|
||||
}
|
||||
if len(parts4) != 1 || parts4[0].Type != "text" || parts4[0].Text != "答" {
|
||||
t.Fatalf("expected visible response text, got %#v", parts4)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSSEChunkForContentAutoTransitionsThinkClose(t *testing.T) {
|
||||
chunk := map[string]any{
|
||||
"p": "response/thinking_content",
|
||||
|
||||
Reference in New Issue
Block a user