Skip to content

Commit

Permalink
add xml syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Feb 13, 2025
1 parent 11550fb commit b6711b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ static common_chat_params common_chat_params_init_hermes_2_pro(const common_chat
"\"<response>\" space " + any_tool_call + " \"</response>\"",
"\"<tools>\" space " + any_tool_call + " \"</tools>\"",
"\"<json>\" space " + any_tool_call + " \"</json>\"",
"\"<xml>\" space " + any_tool_call + " \"</xml>\"",
"\"<JSON>\" space " + any_tool_call + " \"</JSON>\"",
};
auto wrappable_tool_call = builder.add_rule("wrappable_tool_call", "( " + string_join(alt_tags, " | ") + " ) space");
Expand All @@ -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({"<function_call>", /* .at_start = */ true});
data.grammar_triggers.push_back({"<tools>", /* .at_start = */ true});
data.grammar_triggers.push_back({"<xml>", /* .at_start = */ true});
data.grammar_triggers.push_back({"<response>", /* .at_start = */ true});
data.grammar_triggers.push_back({"```\n{\"name\":", /* .at_start = */ true});
data.grammar_triggers.push_back({"```\n {\"name\":", /* .at_start = */ true});
Expand Down Expand Up @@ -1066,6 +1068,7 @@ static common_chat_msg common_chat_parse_hermes_2_pro(const std::string& input)
"|<tools>"
"|<response>"
"|<json>"
"|<xml>"
"|<JSON>"
")?"
"(\\s*\\{\\s*\"name\":[\\s\\S]*)" // match 3 (named tool call + rest)
Expand Down
7 changes: 7 additions & 0 deletions tests/test-chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ static void test_template_output_parsers() {
" {\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}\n"
"</json>",
COMMON_CHAT_FORMAT_HERMES_2_PRO));
assert_msg_equals(msg_from_json(message_assist_call), common_chat_parse(
"<xml>\n"
" {\n"
" \"name\": \"special_function\", \"arguments\": {\"arg1\": 1}\n"
" }\n"
"</xml>",
COMMON_CHAT_FORMAT_HERMES_2_PRO));
assert_msg_equals(msg_from_json(message_assist_call), common_chat_parse(
"<JSON>\n"
" {\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}\n"
Expand Down

0 comments on commit b6711b8

Please sign in to comment.