tool-call
: accept {"type": "function", "name": "fn"
for llama 3.x
This commit is contained in:
parent
241acc2488
commit
332506910f
2 changed files with 8 additions and 2 deletions
|
@ -185,7 +185,7 @@ static llama_tool_calls parse_llama_3_tool_calls(const json & tools, const std::
|
|||
};
|
||||
}
|
||||
}
|
||||
static std::regex function_regex("\\{[\\s\\n\\r]*\"name\": \"([^\"]+)\", \"parameters\": ");
|
||||
static std::regex function_regex("\\{(?:\"type\": \"function\", |[\\s\\n\\r]*)\"name\": \"([^\"]+)\", \"parameters\": ");
|
||||
static std::regex close_regex("\\}");
|
||||
return parse_json_tool_calls(tools, input, function_regex, close_regex, /* check_names= */ true);
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ llama_tool_call_handler llama_tool_call_handler_init(
|
|||
tool_rules.push_back(
|
||||
builder.add_rule(
|
||||
name + "-call",
|
||||
"\"\\n\"? \"{\" space \"\\\"name\\\": \\\"" + name + "\\\", \\\"parameters\\\": \" " +
|
||||
"\"\\n\"? \"{\" ( \"\\\"type\\\": \\\"function\\\", \" | space ) \"\\\"name\\\": \\\"" + name + "\\\", \\\"parameters\\\": \" " +
|
||||
builder.add_schema(name + "-args", parameters) +
|
||||
" \"}\""));
|
||||
if (allow_content && !eagerly_match_any_json) {
|
||||
|
@ -281,6 +281,7 @@ llama_tool_call_handler llama_tool_call_handler_init(
|
|||
handler.grammar_trigger_words.push_back("{\n\t\"name\": \"" + name + "\"");
|
||||
handler.grammar_trigger_words.push_back("{\n \"name\": \"" + name + "\"");
|
||||
handler.grammar_trigger_words.push_back("{\n \"name\": \"" + name + "\"");
|
||||
handler.grammar_trigger_words.push_back("{\"type\": \"function\", \"name\": \"" + name + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -253,6 +253,11 @@ static void test_parsing() {
|
|||
"{\n \"name\": \"special_function\", \"parameters\": {\"arg1\": 1}}",
|
||||
"",
|
||||
just_special_function_call);
|
||||
test_parse_tool_call(llama_tool_call_style::Llama31, tools,
|
||||
"{\"type\": \"function\", \"name\": \"special_function\", \"parameters\": {\"arg1\": 1}}",
|
||||
"",
|
||||
just_special_function_call);
|
||||
|
||||
// No match: function unknown
|
||||
test_parse_tool_call(llama_tool_call_style::Llama31, tools,
|
||||
"{\"name\": \"unknown_function\", \"arguments\": {\"arg1\": 1}}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue