server: allow unclosed thinking tags (#13931)

This commit is contained in:
Olivier Chafik
2025-05-31 08:26:10 -07:00
committed by GitHub
parent 803f8baf4f
commit e15898d1c7
2 changed files with 13 additions and 3 deletions

View File

@ -154,9 +154,10 @@ bool common_chat_msg_parser::try_parse_reasoning(const std::string & start_think
if (!rest.empty()) { if (!rest.empty()) {
handle_reasoning(rest, /* closed */ !is_partial()); handle_reasoning(rest, /* closed */ !is_partial());
} }
if (!syntax_.thinking_forced_open) { // Allow unclosed thinking tags, for now (https://github.com/ggml-org/llama.cpp/issues/13812, https://github.com/ggml-org/llama.cpp/issues/13877)
throw common_chat_msg_partial_exception(end_think); // if (!syntax_.thinking_forced_open) {
} // throw common_chat_msg_partial_exception(end_think);
// }
return true; return true;
} }
} }

View File

@ -1041,6 +1041,15 @@ static void test_template_output_parsers() {
"<tool_call>\n" "<tool_call>\n"
"{\"name\": \"python\", \"arguments\": {\"code\":\"# This is a program:\\nprint('hey')\"}}\n" "{\"name\": \"python\", \"arguments\": {\"code\":\"# This is a program:\\nprint('hey')\"}}\n"
"</tool_call>"); "</tool_call>");
assert_msg_equals(
simple_assist_msg("", /* reasoning_content= */ "<tool_call>nah uhg</tool_call>"),
common_chat_parse(
"<think><tool_call>nah uhg</tool_call>",
/* is_partial= */ false,
{
/* .format = */ COMMON_CHAT_FORMAT_HERMES_2_PRO,
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
}));
} }
{ {
auto tmpls = read_templates("models/templates/meta-llama-Llama-3.1-8B-Instruct.jinja"); auto tmpls = read_templates("models/templates/meta-llama-Llama-3.1-8B-Instruct.jinja");