fix: inject English system prompt for DeepSeek provider
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

DeepSeek models default to Chinese for some prompts. The ensureEnglish()
function prepends 'Always respond in English' as a system message when
no system prompt is already set. Applied to both ChatCompletion and
ChatCompletionStream paths.
This commit is contained in:
2026-05-07 14:03:39 -04:00
parent eb585c0001
commit 28b8271c1d
2 changed files with 21 additions and 0 deletions
+16
View File
@@ -445,3 +445,19 @@ func StreamGemini(ctx io.ReadCloser, ch chan<- *models.ChatCompletionStreamRespo
return nil
}
// ensureEnglish injects a system message instructing the model to respond in
// English when no system prompt is already present. Some providers (e.g. DeepSeek)
// default to Chinese for certain prompts.
func ensureEnglish(req *models.UnifiedRequest) {
if len(req.Messages) > 0 && req.Messages[0].Role == "system" {
return // already has a system prompt, don't interfere
}
enMsg := models.UnifiedMessage{
Role: "system",
Content: []models.UnifiedContentPart{
{Type: "text", Text: "You are a helpful assistant. Always respond in English."},
},
}
req.Messages = append([]models.UnifiedMessage{enMsg}, req.Messages...)
}