Skip to content

Commit 7bff802

Browse files
aldehirrsenthilkumar6
authored andcommitted
common/autoparser : allow space after tool call (ggml-org#22073)
1 parent ca2f198 commit 7bff802

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

common/chat-auto-parser-generator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ common_peg_parser analyze_tools::build_tool_parser_tag_tagged(parser_build_conte
443443
if (!format.per_call_start.empty()) {
444444
auto wrapped_call = format.per_call_start + p.space() + tool_choice + p.space() + format.per_call_end;
445445
if (inputs.parallel_tool_calls) {
446-
tool_calls = p.trigger_rule("tool-call", wrapped_call + p.zero_or_more(p.space() + wrapped_call));
446+
tool_calls = p.trigger_rule("tool-call", wrapped_call + p.zero_or_more(p.space() + wrapped_call) + p.space());
447447
} else {
448-
tool_calls = p.trigger_rule("tool-call", wrapped_call);
448+
tool_calls = p.trigger_rule("tool-call", wrapped_call + p.space());
449449
}
450450
if (!format.section_start.empty()) {
451451
tool_calls = p.trigger_rule("tool-calls",
452452
p.literal(format.section_start) + p.space() + tool_calls + p.space() +
453-
(format.section_end.empty() ? p.end() : p.literal(format.section_end)));
453+
(format.section_end.empty() ? p.end() : p.literal(format.section_end) + p.space()));
454454
}
455455
} else {
456456
std::string separator = ", "; // Default

tests/test-chat.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
17961796
"<function=special_function>\n"
17971797
"<parameter=arg1>\n1\n</parameter>\n"
17981798
"</function>\n"
1799-
"</tool_call>")
1799+
"</tool_call>\n")
18001800
.enable_thinking(false)
18011801
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
18021802
.tools({ special_function_tool })
@@ -1809,7 +1809,7 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
18091809
"<function=special_function>\n"
18101810
"<parameter=arg1>\n1\n</parameter>\n"
18111811
"</function>\n"
1812-
"</tool_call>")
1812+
"</tool_call>\n")
18131813
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
18141814
.tools({ special_function_tool })
18151815
.expect(message_assist_call_thoughts)
@@ -1826,7 +1826,7 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
18261826
"<parameter=arg1>\n1\n</parameter>\n"
18271827
"<parameter=arg2>\n2\n</parameter>\n"
18281828
"</function>\n"
1829-
"</tool_call>")
1829+
"</tool_call>\n")
18301830
.enable_thinking(false)
18311831
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
18321832
.parallel_tool_calls(true)
@@ -1849,7 +1849,7 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
18491849
"hello()\n"
18501850
"</parameter>\n"
18511851
"</function>\n"
1852-
"</tool_call>")
1852+
"</tool_call>\n")
18531853
.enable_thinking(false)
18541854
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
18551855
.tools({
@@ -1892,7 +1892,7 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
18921892
"hello()\n"
18931893
"</parameter>\n"
18941894
"</function>\n"
1895-
"</tool_call>"
1895+
"</tool_call>\n"
18961896
)
18971897
.enable_thinking(true)
18981898
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
@@ -1908,7 +1908,7 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
19081908
"hello()\n"
19091909
"</parameter>\n"
19101910
"</function>\n"
1911-
"</tool_call>")
1911+
"</tool_call>\n")
19121912
.expect_tool_calls({
19131913
{ "python", "{\"code\": \"def hello():\\n print(\\\"Hello, world!\\\")\\n\\nhello()\"}", {} },
19141914
})

0 commit comments

Comments
 (0)