Skip to content

Commit e15898d

Browse files
authored
server: allow unclosed thinking tags (#13931)
1 parent 803f8ba commit e15898d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

common/chat-parser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ bool common_chat_msg_parser::try_parse_reasoning(const std::string & start_think
154154
if (!rest.empty()) {
155155
handle_reasoning(rest, /* closed */ !is_partial());
156156
}
157-
if (!syntax_.thinking_forced_open) {
158-
throw common_chat_msg_partial_exception(end_think);
159-
}
157+
// Allow unclosed thinking tags, for now (https://github.com/ggml-org/llama.cpp/issues/13812, https://github.com/ggml-org/llama.cpp/issues/13877)
158+
// if (!syntax_.thinking_forced_open) {
159+
// throw common_chat_msg_partial_exception(end_think);
160+
// }
160161
return true;
161162
}
162163
}

tests/test-chat.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,15 @@ static void test_template_output_parsers() {
10411041
"<tool_call>\n"
10421042
"{\"name\": \"python\", \"arguments\": {\"code\":\"# This is a program:\\nprint('hey')\"}}\n"
10431043
"</tool_call>");
1044+
assert_msg_equals(
1045+
simple_assist_msg("", /* reasoning_content= */ "<tool_call>nah uhg</tool_call>"),
1046+
common_chat_parse(
1047+
"<think><tool_call>nah uhg</tool_call>",
1048+
/* is_partial= */ false,
1049+
{
1050+
/* .format = */ COMMON_CHAT_FORMAT_HERMES_2_PRO,
1051+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1052+
}));
10441053
}
10451054
{
10461055
auto tmpls = read_templates("models/templates/meta-llama-Llama-3.1-8B-Instruct.jinja");

0 commit comments

Comments
 (0)