File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -642,18 +642,18 @@ static json oaicompat_completion_params_parse(
642642 throw std::runtime_error (" Cannot use custom grammar constraints with tools." );
643643 }
644644
645- /* sanity check, max one assistant message at the end of the list */
646- bool last_message_is_assistant = inputs.messages .size () > 0 && inputs.messages .back ().role == " assistant" ;
647- if (last_message_is_assistant && inputs.messages .size () >= 2 && inputs.messages [inputs.messages .size ()-2 ].role == " assistant" ) {
648- throw std::runtime_error (" Cannot have 2 or more assistant messages at the end of the list." );
649- }
650-
651645 /* Prefill assistant message support */
652- bool prefill_assistant_message = last_message_is_assistant ;
646+ bool prefill_assistant_message = !inputs. messages . empty () && inputs. messages . back (). role == " assistant " ;
653647 common_chat_msg last_message;
654648 if (prefill_assistant_message) {
655649 last_message = inputs.messages .back ();
656650 inputs.messages .pop_back ();
651+
652+ /* sanity check, max one assistant message at the end of the list */
653+ if (!inputs.messages .empty () && inputs.messages .back ().role == " assistant" ){
654+ throw std::runtime_error (" Cannot have 2 or more assistant messages at the end of the list." );
655+ }
656+
657657 inputs.extract_reasoning = false ;
658658 inputs.add_generation_prompt = true ;
659659 }
You can’t perform that action at this time.
0 commit comments