mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-22 00:47:45 +08:00
chore: update project files
This commit is contained in:
@@ -30,11 +30,6 @@ func MessagesPrepareWithThinking(messages []map[string]any, thinkingEnabled bool
|
||||
Text string
|
||||
}
|
||||
processed := make([]block, 0, len(messages))
|
||||
if thinkingEnabled {
|
||||
if instruction := buildConversationContinuityInstructions(thinkingEnabled); strings.TrimSpace(instruction) != "" {
|
||||
processed = append(processed, block{Role: "system", Text: instruction})
|
||||
}
|
||||
}
|
||||
for _, m := range messages {
|
||||
role, _ := m["role"].(string)
|
||||
text := NormalizeContent(m["content"])
|
||||
@@ -93,17 +88,6 @@ func formatRoleBlock(marker, text, endMarker string) string {
|
||||
return out
|
||||
}
|
||||
|
||||
func buildConversationContinuityInstructions(thinkingEnabled bool) string {
|
||||
lines := []string{
|
||||
"Continue the conversation from the full prior context and the latest tool results.",
|
||||
"Treat earlier messages as binding context; answer the user's current request as a continuation, not a restart.",
|
||||
}
|
||||
if thinkingEnabled {
|
||||
lines = append(lines, "Keep reasoning internal. Do not leave the final user-facing answer only in reasoning; always provide the answer in visible assistant content.")
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
func NormalizeContent(v any) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
|
||||
@@ -58,23 +58,14 @@ func TestNormalizeContentArrayFallsBackToContentWhenTextEmpty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessagesPrepareWithThinkingAddsContinuityContract(t *testing.T) {
|
||||
func TestMessagesPrepareWithThinkingPreservesPromptShape(t *testing.T) {
|
||||
messages := []map[string]any{{"role": "user", "content": "Question"}}
|
||||
gotThinking := MessagesPrepareWithThinking(messages, true)
|
||||
gotPlain := MessagesPrepareWithThinking(messages, false)
|
||||
if gotThinking == gotPlain {
|
||||
t.Fatalf("expected thinking-enabled prompt to include extra continuity instructions")
|
||||
if gotThinking != gotPlain {
|
||||
t.Fatalf("expected thinking flag not to add extra continuity instructions, got thinking=%q plain=%q", gotThinking, gotPlain)
|
||||
}
|
||||
if !strings.HasSuffix(gotThinking, "<|Assistant|>") {
|
||||
t.Fatalf("expected assistant suffix, got %q", gotThinking)
|
||||
}
|
||||
if !strings.Contains(gotThinking, "Continue the conversation from the full prior context") {
|
||||
t.Fatalf("expected continuity instruction in thinking prompt, got %q", gotThinking)
|
||||
}
|
||||
if !strings.Contains(gotThinking, "final user-facing answer only in reasoning") {
|
||||
t.Fatalf("expected visible-answer instruction in thinking prompt, got %q", gotThinking)
|
||||
}
|
||||
if strings.Contains(gotPlain, "Continue the conversation from the full prior context") {
|
||||
t.Fatalf("did not expect thinking-only instruction in plain prompt, got %q", gotPlain)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user