From b6711b8319e8072957fd8e98d908b3152bffc228 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Thu, 13 Feb 2025 19:15:30 +0000 Subject: [PATCH] add xml syntax --- common/chat.cpp | 3 +++ tests/test-chat.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/common/chat.cpp b/common/chat.cpp index 006f0041e1afd..a9397fe9a727c 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -1015,6 +1015,7 @@ static common_chat_params common_chat_params_init_hermes_2_pro(const common_chat "\"\" space " + any_tool_call + " \"\"", "\"\" space " + any_tool_call + " \"\"", "\"\" space " + any_tool_call + " \"\"", + "\"\" space " + any_tool_call + " \"\"", "\"\" space " + any_tool_call + " \"\"", }; auto wrappable_tool_call = builder.add_rule("wrappable_tool_call", "( " + string_join(alt_tags, " | ") + " ) space"); @@ -1028,6 +1029,7 @@ static common_chat_params common_chat_params_init_hermes_2_pro(const common_chat // Trigger on some common known "good bad" outputs (only from the start to avoid false positives) // data.grammar_triggers.push_back({"", /* .at_start = */ true}); data.grammar_triggers.push_back({"", /* .at_start = */ true}); + data.grammar_triggers.push_back({"", /* .at_start = */ true}); data.grammar_triggers.push_back({"", /* .at_start = */ true}); data.grammar_triggers.push_back({"```\n{\"name\":", /* .at_start = */ true}); data.grammar_triggers.push_back({"```\n {\"name\":", /* .at_start = */ true}); @@ -1066,6 +1068,7 @@ static common_chat_msg common_chat_parse_hermes_2_pro(const std::string& input) "|" "|" "|" + "|" "|" ")?" "(\\s*\\{\\s*\"name\":[\\s\\S]*)" // match 3 (named tool call + rest) diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp index 990173f0c809e..5ce9994521369 100644 --- a/tests/test-chat.cpp +++ b/tests/test-chat.cpp @@ -642,6 +642,13 @@ static void test_template_output_parsers() { " {\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}\n" "", COMMON_CHAT_FORMAT_HERMES_2_PRO)); + assert_msg_equals(msg_from_json(message_assist_call), common_chat_parse( + "\n" + " {\n" + " \"name\": \"special_function\", \"arguments\": {\"arg1\": 1}\n" + " }\n" + "", + COMMON_CHAT_FORMAT_HERMES_2_PRO)); assert_msg_equals(msg_from_json(message_assist_call), common_chat_parse( "\n" " {\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}\n"