multiturn tests

This commit is contained in:
Grace Guo
2025-11-26 15:23:48 -08:00
parent 5ca9109612
commit 22baf302f1
2 changed files with 45 additions and 6 deletions

View File

@@ -71,20 +71,17 @@ func (r *DeepSeekRenderer) Render(messages []api.Message, tools []api.Tool, thin
sb.WriteString("<tool▁calls▁end><end▁of▁sentence>")
} else {
if isLastUser {
sb.WriteString("<Assistant>")
if enableThinking {
sb.WriteString("<think>")
} else {
sb.WriteString("</think>")
}
sb.WriteString("<Assistant></think>")
}
isLastUser = false
content := message.Content
if isToolContext {
sb.WriteString(content + "<end▁of▁sentence>")
isToolContext = false
} else {
// Remove any existing </think> tags from content (matching Jinja behavior)
if strings.Contains(content, "</think>") {
parts := strings.SplitN(content, "</think>", 2)
if len(parts) > 1 {

View File

@@ -16,6 +16,45 @@ func TestDeepSeekRenderer(t *testing.T) {
thinkValue *api.ThinkValue
expected string
}{
{
name: "debug multi-turn conversation",
messages: []api.Message{
{Role: "user", Content: "hey!"},
{Role: "assistant", Content: "Hey there! 👋 How's it going?"},
{Role: "user", Content: "how are you?"},
},
thinkValue: &api.ThinkValue{Value: true},
expected: `<begin▁of▁sentence><User>hey!<Assistant></think>Hey there! 👋 How's it going?<end▁of▁sentence><User>how are you?<Assistant><think>`,
},
{
name: "historical message with thinking field",
messages: []api.Message{
{Role: "user", Content: "hello"},
{
Role: "assistant",
Thinking: "The user is greeting me, I should respond politely.",
Content: "Hello! How can I help you today?",
},
{Role: "user", Content: "thanks"},
},
thinkValue: &api.ThinkValue{Value: false},
expected: `<begin▁of▁sentence><User>hello<Assistant></think>Hello! How can I help you today?<end▁of▁sentence><User>thanks<Assistant></think>`,
},
{
name: "conversation with thinking enabled",
messages: []api.Message{
{Role: "user", Content: "hey!"},
{
Role: "assistant",
Content: `Hey there! 😊 How's your day going? What can I help you with today - whether it's answering
questions, brainstorming ideas, or just having a chat?!`,
},
{Role: "user", Content: "chat"},
},
thinkValue: &api.ThinkValue{Value: true},
expected: `<begin▁of▁sentence><User>hey!<Assistant></think>Hey there! 😊 How's your day going? What can I help you with today - whether it's answering
questions, brainstorming ideas, or just having a chat?!<end▁of▁sentence><User>chat<Assistant><think>`,
},
{
name: "basic user message",
messages: []api.Message{
@@ -280,6 +319,9 @@ Second instruction<User>Hello<Assistant></think>`,
if err != nil {
t.Fatalf("Render() error = %v", err)
}
if tt.name == "debug multi-turn conversation" {
t.Logf("Actual rendered output: %q", rendered)
}
if diff := cmp.Diff(tt.expected, rendered); diff != "" {
t.Errorf("Render() mismatch (-want +got):\n%s", diff)
}