]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server: allow unclosed thinking tags (#13931)
authorOlivier Chafik <redacted>
Sat, 31 May 2025 15:26:10 +0000 (08:26 -0700)
committerGitHub <redacted>
Sat, 31 May 2025 15:26:10 +0000 (08:26 -0700)
common/chat-parser.cpp
tests/test-chat.cpp

index c314b8b519913a8ef0bb007b0869e80e2c37b7b6..65b664cb37da44d28fba63d6e39dccbf734f4613 100644 (file)
@@ -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;
         }
     }
index cd5827aa32b3b1e131ddaa3c069bafd2f8dd58b4..1c98079217235ad1b985187538646bf467677eff 100644 (file)
@@ -1041,6 +1041,15 @@ static void test_template_output_parsers() {
                       "<tool_call>\n"
                       "{\"name\": \"python\", \"arguments\": {\"code\":\"# This is a program:\\nprint('hey')\"}}\n"
                       "</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");