mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-12 04:07:42 +08:00
refactor: enhance XML tool call parsing to support nested structures, CDATA, and repeated tags
This commit is contained in:
@@ -12,7 +12,7 @@ func TestMessagesPrepareBasic(t *testing.T) {
|
||||
if got == "" {
|
||||
t.Fatal("expected non-empty prompt")
|
||||
}
|
||||
if got != "<|begin▁of▁sentence|><|User|>Hello<|Assistant|></think>" {
|
||||
if got != "<|begin▁of▁sentence|><|User|>Hello<|Assistant|>" {
|
||||
t.Fatalf("unexpected prompt: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -32,10 +32,10 @@ func TestMessagesPrepareRoles(t *testing.T) {
|
||||
if !contains(got, "<|begin▁of▁sentence|>") {
|
||||
t.Fatalf("expected begin marker in %q", got)
|
||||
}
|
||||
if !contains(got, "<|User|>Hi<|Assistant|></think>Hello<|end▁of▁sentence|>") {
|
||||
if !contains(got, "<|User|>Hi<|Assistant|>Hello<|end▁of▁sentence|>") {
|
||||
t.Fatalf("expected user/assistant separation in %q", got)
|
||||
}
|
||||
if !contains(got, "<|Assistant|></think>Hello<|end▁of▁sentence|><|Tool|>Search results<|end▁of▁toolresults|>") {
|
||||
if !contains(got, "<|Assistant|>Hello<|end▁of▁sentence|><|Tool|>Search results<|end▁of▁toolresults|>") {
|
||||
t.Fatalf("expected assistant/tool separation in %q", got)
|
||||
}
|
||||
if !contains(got, "<|Tool|>Search results<|end▁of▁toolresults|><|User|>How are you") {
|
||||
@@ -77,7 +77,7 @@ func TestMessagesPrepareArrayTextVariants(t *testing.T) {
|
||||
},
|
||||
}
|
||||
got := MessagesPrepare(messages)
|
||||
if got != "<|begin▁of▁sentence|><|User|>line1\nline2<|Assistant|></think>" {
|
||||
if got != "<|begin▁of▁sentence|><|User|>line1\nline2<|Assistant|>" {
|
||||
t.Fatalf("unexpected content from text variants: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,9 +195,12 @@ func TestMessagesPrepareAssistantMarkers(t *testing.T) {
|
||||
if strings.Count(got, "<|end▁of▁sentence|>") != 1 {
|
||||
t.Fatalf("expected one end_of_sentence (assistant only), got %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "<|Assistant|></think>Hello!<|end▁of▁sentence|>") {
|
||||
if !strings.Contains(got, "<|Assistant|>Hello!<|end▁of▁sentence|>") {
|
||||
t.Fatalf("expected assistant EOS suffix, got %q", got)
|
||||
}
|
||||
if strings.Contains(got, "<think>") || strings.Contains(got, "</think>") {
|
||||
t.Fatalf("did not expect think tags in prompt, got %q", got)
|
||||
}
|
||||
if strings.Contains(got, "<system_instructions>") {
|
||||
t.Fatalf("did not expect legacy system marker, got %q", got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user