Skip to content

Commit 5676dfb

Browse files
authored
chat : accept </ifm|think> as K2 Horizon closer at medium/low effort (ggml-org#30335)
1 parent 0a66ac7 commit 5676dfb

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎common/parsers/k2-horizon.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ common_chat_params common_chat_params_init_k2_horizon(const common_chat_template
4848
data.thinking_start_tag = THINK_START;
4949
data.thinking_end_tags = { THINK_END };
5050

51+
// The models sometimes close medium/low reasoning with the generic </ifm|think>
52+
if (think != "ifm|think") {
53+
data.thinking_end_tags.push_back("</ifm|think>");
54+
}
55+
5156
data.preserved_tokens = data.thinking_end_tags;
5257
data.preserved_tokens.insert(data.preserved_tokens.end(), {
5358
THINK_START, SECTION_START, SECTION_END, CALL_START, CALL_END,

‎tests/test-chat.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,6 +5206,25 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
52065206
.expect_reconstruction()
52075207
.run();
52085208

5209+
tst.test("I'm\nthinking</ifm|think>Hello, world!\nWhat's up?")
5210+
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
5211+
.chat_template_kwargs({ { "reasoning_effort", R"("low")" } })
5212+
.expect(message_assist_thoughts)
5213+
.run();
5214+
5215+
tst.test(
5216+
"I'm\nthinking</ifm|think><ifm|tool_calls>\n"
5217+
"<ifm|tool_call>special_function\n"
5218+
"<ifm|arg_key>arg1</ifm|arg_key>\n"
5219+
"<ifm|arg_value>1</ifm|arg_value>\n"
5220+
"</ifm|tool_call>\n"
5221+
"</ifm|tool_calls>")
5222+
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
5223+
.tools({ special_function_tool })
5224+
.chat_template_kwargs({ { "reasoning_effort", R"("medium")" } })
5225+
.expect(message_assist_call_thoughts)
5226+
.run();
5227+
52095228
tst.test(
52105229
"I'm\nthinking</ifm|think><ifm|tool_calls>\n"
52115230
"<ifm|tool_call>{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}</ifm|tool_call>\n"

0 commit comments

Comments
 (0)