| 1 | package config |
| 2 | |
| 3 | import "strings" |
| 4 | |
| 5 | // OfficialDeepSeekV4ProPersona is prepended to the cache-stable system prompt |
| 6 | // for official DeepSeek-V4-Pro. That model's agent post-training is peaked on |
| 7 | // this first-line persona and English "We need" thinking. |
| 8 | const OfficialDeepSeekV4ProPersona = `You are a helpful software engineer assistant. when you thought, thought in ENGLISH, start with "We need.."` |
| 9 | |
| 10 | // AppliesOfficialDeepSeekV4ProPersona reports whether the resolved official |
| 11 | // DeepSeek endpoint is serving V4 Pro. Third-party hosts are excluded even |
| 12 | // when they reuse the same model id. |
| 13 | func AppliesOfficialDeepSeekV4ProPersona(e *ProviderEntry) bool { |
| 14 | if e == nil || officialProviderKind(e) != "deepseek" { |
| 15 | return false |
| 16 | } |
| 17 | return strings.EqualFold(strings.TrimSpace(e.Model), "deepseek-v4-pro") |
| 18 | } |
| 19 | |
| 20 | // ApplyOfficialDeepSeekV4ProPersona keeps the persona as the first system-prompt |
| 21 | // paragraph for official V4 Pro and strips it when the session is not that model. |
| 22 | func ApplyOfficialDeepSeekV4ProPersona(prompt string, e *ProviderEntry) string { |
| 23 | prompt = stripOfficialDeepSeekV4ProPersona(prompt) |
| 24 | if !AppliesOfficialDeepSeekV4ProPersona(e) { |
| 25 | return prompt |
| 26 | } |
| 27 | if strings.TrimSpace(prompt) == "" { |
| 28 | return OfficialDeepSeekV4ProPersona |
| 29 | } |
| 30 | return OfficialDeepSeekV4ProPersona + "\n\n" + prompt |
| 31 | } |
| 32 | |
| 33 | func stripOfficialDeepSeekV4ProPersona(prompt string) string { |
| 34 | switch { |
| 35 | case strings.HasPrefix(prompt, OfficialDeepSeekV4ProPersona+"\n\n"): |
| 36 | return strings.TrimPrefix(prompt, OfficialDeepSeekV4ProPersona+"\n\n") |
| 37 | case strings.HasPrefix(prompt, OfficialDeepSeekV4ProPersona+"\n"): |
| 38 | return strings.TrimPrefix(prompt, OfficialDeepSeekV4ProPersona+"\n") |
| 39 | case prompt == OfficialDeepSeekV4ProPersona: |
| 40 | return "" |
| 41 | default: |
| 42 | return prompt |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // ReasoningLanguageForEntry pins official V4 Pro auto mode to English so the |
| 47 | // per-turn Chinese auto-inference cannot override the persona. |
| 48 | func ReasoningLanguageForEntry(e *ProviderEntry, configured string) string { |
| 49 | if AppliesOfficialDeepSeekV4ProPersona(e) && NormalizeReasoningLanguage(configured) == "auto" { |
| 50 | return "en" |
| 51 | } |
| 52 | return configured |
| 53 | } |
| 54 |