File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -642,9 +642,26 @@ static json oaicompat_completion_params_parse(
642642 throw std::runtime_error (" Cannot use custom grammar constraints with tools." );
643643 }
644644
645+ /* Prefill assistant message support */
646+ bool prefill_assistant_message = inputs.messages .size () > 0 && inputs.messages [inputs.messages .size ()-1 ].role == " assistant" ;
647+ common_chat_msg last_message;
648+ if (prefill_assistant_message)
649+ {
650+ last_message = inputs.messages .back ();
651+ inputs.messages .pop_back ();
652+ inputs.extract_reasoning = false ;
653+ inputs.add_generation_prompt = true ;
654+ }
655+
645656 // Apply chat template to the list of messages
646657 auto chat_params = common_chat_templates_apply (tmpls, inputs);
647658
659+ /* Append assistant prefilled message */
660+ if (prefill_assistant_message)
661+ {
662+ chat_params.prompt += last_message.content ;
663+ }
664+
648665 llama_params[" chat_format" ] = static_cast <int >(chat_params.format );
649666 llama_params[" prompt" ] = chat_params.prompt ;
650667 if (!chat_params.grammar .empty ()) {
You can’t perform that action at this time.
0 commit comments