Skip to content

Commit aa5694f

Browse files
author
ochafik
committed
Fix phi-4 grammar (needs <|tool_call|> wrappers)
1 parent 4de63f3 commit aa5694f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

common/chat.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,14 +1359,15 @@ static common_chat_params common_chat_params_init_phi_4(const common_chat_templa
13591359
std::string name = function.at("name");
13601360
auto parameters = function.at("parameters");
13611361
builder.resolve_refs(parameters);
1362-
tool_rules.push_back(builder.add_schema(name + "-call", {
1362+
auto call_rule = builder.add_schema(name + "-call", {
13631363
{"type", "object"},
13641364
{"properties", {
13651365
{"name", {{"const", name}}},
13661366
{"arguments", parameters},
13671367
}},
13681368
{"required", json::array({"name", "arguments"})},
1369-
}));
1369+
});
1370+
tool_rules.push_back(builder.add_rule(name + "-call", "\"<|tool_call|>\" " + call_rule + " \"<|/tool_call|>\""));
13701371
});
13711372
auto any_tool_call = builder.add_rule("any_tool_call", "( " + string_join(tool_rules, " | ") + " ) space");
13721373
std::vector<std::string> alt_tags {

0 commit comments

Comments
 (0)