fix: inject English system prompt for DeepSeek provider
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:
@@ -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...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user