Skip to content

Commit cb7fe04

Browse files
author
matteo
committed
merge checks into prefill code
1 parent 0c316cd commit cb7fe04

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

examples/server/utils.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)