Chat Completions 协议下自定义系统提示词被静默忽略(custom system prompt dropped on chat protocol)
现象
配置并激活自定义系统提示词(System Prompt Management / system-prompt.json)后,在 Request Method = OpenAI Chat Completion 的 profile 下对话,自定义提示词完全不进请求:messages[0] 只有内置 You are Snow AI CLI ...,没有用户配置的内容。
切换到 Responses 协议则正常(自定义内容进入 instructions)。
- 版本:
snow-ai v0.8.7 - 与 #177 是姊妹问题:#177 的修复仅覆盖 Responses 协议,未覆盖 Chat。
复现步骤
- 在 System Prompt Management 配置并激活一个自定义系统提示词;
- 用一个 Chat Completion 协议的 profile 发送任意消息;
- 抓请求体,
messages里只有内置 system 消息,无自定义内容。
根因
source/api/chat.ts 的 convertToOpenAIMessages(约 116 行),244–246 行有一道守卫:
// 如果第一条消息已经是 system 消息,跳过
if (result.length > 0 && result[0]?.role === 'system') {
return result;
}
默认会话流程中 sessionInitializer 总会把内置系统提示词作为第一条 system 消息注入(messages[0]),因此该守卫命中,函数在到达 249 行起的自定义提示词注入逻辑之前就 return 了 → customSystemPrompts 被丢弃。
对比 responses.ts / gemini.ts / anthropic.ts:它们会把 system 消息抽进系统字段并应用自定义提示词,所以这些协议正常;唯独 Chat 协议因这道 early-return 丢失自定义提示词。
建议修法
首条已是内置 system 消息时,不应直接 return,应仍然注入自定义提示词(只跳过内置提示词的重复添加):
if (result.length > 0 && result[0]?.role === 'system') {
if (customSystemPrompts && customSystemPrompts.length > 0) {
result.unshift({
role: 'system',
content: customSystemPrompts.map(text => ({type: 'text', text})),
});
}
return result;
}
即把自定义提示词作为额外的 system 消息前置(或并入现有 system 消息),内置仍只出现一次。
影响
用户配置的全局 / 自定义系统提示词在所有 Chat Completion 协议的 profile 下静默失效,无报错、难以察觉。Responses 协议不受影响。
已修复:https://github.com/MayDay-wpf/snow-cli/commit/f6fa2eb48b038edf5d2ba9a159f9a263fa1708c5