From 92517e74ad9aa2703b641106d5d6dc9e42610883 Mon Sep 17 00:00:00 2001 From: jarrodfeaks <85427306+jarrodfeaks@users.noreply.github.com> Date: Thu, 30 Oct 2025 02:21:05 +1100 Subject: [PATCH] fix v1/chat/completions assistant prefill (#874) --- examples/server/utils.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index 565a86ca..dfccea63 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -591,6 +591,17 @@ static json oaicompat_chat_params_parse( // Apply chat template to the list of messages auto chat_params = common_chat_templates_apply(opt.tmpls, inputs); + + /* Append assistant prefilled message */ + if (prefill_assistant_message) { + if (!last_message.content_parts.empty()) { + for (auto & p : last_message.content_parts) { + chat_params.prompt += p.text; + } + } else { + chat_params.prompt += last_message.content; + } + } llama_params["chat_format"] = static_cast(chat_params.format); llama_params["prompt"] = chat_params.prompt;