From e15898d1c7e87f1b3d14e0a3c385eeb424b085fe Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Sat, 31 May 2025 08:26:10 -0700 Subject: [PATCH] server: allow unclosed thinking tags (#13931) --- common/chat-parser.cpp | 7 ++++--- tests/test-chat.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/chat-parser.cpp b/common/chat-parser.cpp index c314b8b51..65b664cb3 100644 --- a/common/chat-parser.cpp +++ b/common/chat-parser.cpp @@ -154,9 +154,10 @@ bool common_chat_msg_parser::try_parse_reasoning(const std::string & start_think if (!rest.empty()) { handle_reasoning(rest, /* closed */ !is_partial()); } - if (!syntax_.thinking_forced_open) { - throw common_chat_msg_partial_exception(end_think); - } + // Allow unclosed thinking tags, for now (https://github.com/ggml-org/llama.cpp/issues/13812, https://github.com/ggml-org/llama.cpp/issues/13877) + // if (!syntax_.thinking_forced_open) { + // throw common_chat_msg_partial_exception(end_think); + // } return true; } } diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp index cd5827aa3..1c9807921 100644 --- a/tests/test-chat.cpp +++ b/tests/test-chat.cpp @@ -1041,6 +1041,15 @@ static void test_template_output_parsers() { "\n" "{\"name\": \"python\", \"arguments\": {\"code\":\"# This is a program:\\nprint('hey')\"}}\n" ""); + assert_msg_equals( + simple_assist_msg("", /* reasoning_content= */ "nah uhg"), + common_chat_parse( + "nah uhg", + /* 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");