Skip to content

Commit c029d97

Browse files
authored
fix v1/chat/completions assistant prefill (ikawrakow#874)
1 parent c33f39d commit c029d97

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

examples/server/utils.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,17 @@ static json oaicompat_chat_params_parse(
591591

592592
// Apply chat template to the list of messages
593593
auto chat_params = common_chat_templates_apply(opt.tmpls, inputs);
594+
595+
/* Append assistant prefilled message */
596+
if (prefill_assistant_message) {
597+
if (!last_message.content_parts.empty()) {
598+
for (auto & p : last_message.content_parts) {
599+
chat_params.prompt += p.text;
600+
}
601+
} else {
602+
chat_params.prompt += last_message.content;
603+
}
604+
}
594605

595606
llama_params["chat_format"] = static_cast<int>(chat_params.format);
596607
llama_params["prompt"] = chat_params.prompt;

0 commit comments

Comments
 (0)