Commit 5676dfbe0 for llama.cpp
commit 5676dfbe01e7ebe0387913680eee0ed39bf4a363
Author: Awss <gitj.18@alt.awss1i.com>
Date: Thu Nov 12 23:11:58 2026 +0000
chat : accept </ifm|think> as K2 Horizon closer at medium/low effort (#30335)
diff --git a/common/parsers/k2-horizon.cpp b/common/parsers/k2-horizon.cpp
index 1afd578c8..e688cd919 100644
--- a/common/parsers/k2-horizon.cpp
+++ b/common/parsers/k2-horizon.cpp
@@ -48,6 +48,11 @@ common_chat_params common_chat_params_init_k2_horizon(const common_chat_template
data.thinking_start_tag = THINK_START;
data.thinking_end_tags = { THINK_END };
+ // The models sometimes close medium/low reasoning with the generic </ifm|think>
+ if (think != "ifm|think") {
+ data.thinking_end_tags.push_back("</ifm|think>");
+ }
+
data.preserved_tokens = data.thinking_end_tags;
data.preserved_tokens.insert(data.preserved_tokens.end(), {
THINK_START, SECTION_START, SECTION_END, CALL_START, CALL_END,
diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp
index 2c59d1222..7752015c8 100644
--- a/tests/test-chat.cpp
+++ b/tests/test-chat.cpp
@@ -5206,6 +5206,25 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
.expect_reconstruction()
.run();
+ tst.test("I'm\nthinking</ifm|think>Hello, world!\nWhat's up?")
+ .reasoning_format(COMMON_REASONING_FORMAT_AUTO)
+ .chat_template_kwargs({ { "reasoning_effort", R"("low")" } })
+ .expect(message_assist_thoughts)
+ .run();
+
+ tst.test(
+ "I'm\nthinking</ifm|think><ifm|tool_calls>\n"
+ "<ifm|tool_call>special_function\n"
+ "<ifm|arg_key>arg1</ifm|arg_key>\n"
+ "<ifm|arg_value>1</ifm|arg_value>\n"
+ "</ifm|tool_call>\n"
+ "</ifm|tool_calls>")
+ .reasoning_format(COMMON_REASONING_FORMAT_AUTO)
+ .tools({ special_function_tool })
+ .chat_template_kwargs({ { "reasoning_effort", R"("medium")" } })
+ .expect(message_assist_call_thoughts)
+ .run();
+
tst.test(
"I'm\nthinking</ifm|think><ifm|tool_calls>\n"
"<ifm|tool_call>{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}</ifm|tool_call>\n"