[Bugfix][DeepSeek V4] Handle trailing system messages in prompt rendering (#51262)

Signed-off-by: jiahaoliang <gzliangjiahao@gmail.com>
Signed-off-by: Jiahao Liang <gzliangjiahao@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Jiahao Liang
2026-08-25 07:49:44 +00:00
committed by GitHub
co-authored by Chauncey
parent 23310bc3de
commit 59d7fc92ea
4 changed files with 150 additions and 3 deletions
+9 -1
View File
@@ -374,7 +374,15 @@ def render_message(
prompt += thinking_end_token if thinking_mode != "thinking" else thinking_start_token
prompt += task_sp_token
elif messages[index].get("role") in ["user", "developer"]:
# A trailing system message opens generation, while a system message
# followed by assistant opens that assistant history turn.
elif role in ["user", "developer"] or (
role == "system"
and (
index == len(messages) - 1
or messages[index + 1].get("role") == "assistant"
)
):
# Normal generation: append Assistant + thinking token
prompt += ASSISTANT_SP_TOKEN
if not drop_thinking and thinking_mode == "thinking":