Skip to content

Commit d7ec84f

Browse files
author
ochafik
committed
tool-call: allow <|python_tag|> in functionary-medium-3.1
1 parent 3d2650c commit d7ec84f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

common/tool-call.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,24 @@ llama_tool_call_handler llama_tool_call_handler_init(
253253
});
254254
// handler.parser = parse_functionary_3_2_tool_calls;
255255
} else if (needs_functionary_v3_llama_3_1_tool_call(chat_template)) {
256+
// ./tests/chat/templates/meetkai-functionary-medium-v3.1.jinja
256257
// https://github.com/MeetKai/functionary/blob/main/tests/prompt_test_v3-llama3.1.txt
258+
// TODO: handle tool {type: code_interpreter} as python
257259
handler.grammar = build_grammar([&](const llama_grammar_builder & builder) {
258260
std::vector<std::string> tool_rules;
259261
for (size_t i = 0, n = tools.size(); i < n; i++) {
260262
auto & tool = tools[i];
261263
const auto & function = tool["function"];
262264
std::string name = function["name"];
263265
auto parameters = function["parameters"];
264-
auto tool_rule = builder.add_rule(name + "-call", "\"<function=" + name + ">\" " + builder.add_schema(name + "-args", parameters) + " \"</function>\"");
265-
tool_rules.push_back(tool_rule);
266+
if (name == "python") {
267+
tool_rules.push_back(builder.add_rule("python-call", "\"<|python_tag|>\" .*"));
268+
if (allow_content) {
269+
handler.grammar_trigger_words.push_back("<|python_tag|>");
270+
}
271+
} else {
272+
tool_rules.push_back(builder.add_rule(name + "-call", "\"<function=" + name + ">\" " + builder.add_schema(name + "-args", parameters) + " \"</function>\""));
273+
}
266274
}
267275
auto tool_call = builder.add_rule("tool_call", join(tool_rules.begin(), tool_rules.end(), " | ")) + " space";
268276
builder.add_rule("root", parallel_tool_calls ? "(" + tool_call + ")+" : tool_call);

0 commit comments

Comments
 (0)