File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -642,8 +642,14 @@ 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+
645651 /* Prefill assistant message support */
646- bool prefill_assistant_message = inputs. messages . size () > 0 && inputs. messages . back (). role == " assistant " ;
652+ bool prefill_assistant_message = last_message_is_assistant ;
647653 common_chat_msg last_message;
648654 if (prefill_assistant_message) {
649655 last_message = inputs.messages .back ();
You can’t perform that action at this time.
0 commit comments