mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2025-11-05 09:36:52 +00:00
sync: minja (glm 4.6 & minmax m2 templates) (#16949)
* sync: minja * Sync https://github.com/ochafik/minja/pull/7 (MinMax M2)
This commit is contained in:
11
vendor/minja/chat-template.hpp
vendored
11
vendor/minja/chat-template.hpp
vendored
@@ -192,18 +192,25 @@ class chat_template {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
const json dummy_args_obj {{"argument_needle", "print('Hello, World!')"}};
|
const json dummy_args_obj {{"argument_needle", "print('Hello, World!')"}};
|
||||||
|
const auto contains_arg_needle = [&](const std::string & out_str) {
|
||||||
|
return contains(out_str, "<parameter=argument_needle>")
|
||||||
|
|| contains(out_str, "\"argument_needle\":")
|
||||||
|
|| contains(out_str, "'argument_needle':")
|
||||||
|
|| contains(out_str, ">argument_needle<")
|
||||||
|
|| contains(out_str, "<parameter name=\"argument_needle\">");
|
||||||
|
};
|
||||||
|
|
||||||
// Note: the arguments are rendered in both cases, but may be double-escaped, which we don't want.
|
// Note: the arguments are rendered in both cases, but may be double-escaped, which we don't want.
|
||||||
out = try_raw_render(json::array({
|
out = try_raw_render(json::array({
|
||||||
dummy_user_msg,
|
dummy_user_msg,
|
||||||
make_tool_calls_msg(json::array({make_tool_call("ipython", dummy_args_obj.dump())})),
|
make_tool_calls_msg(json::array({make_tool_call("ipython", dummy_args_obj.dump())})),
|
||||||
}), {}, false);
|
}), {}, false);
|
||||||
auto tool_call_renders_str_arguments = contains(out, "<parameter=argument_needle>") || contains(out, "\"argument_needle\":") || contains(out, "'argument_needle':");
|
auto tool_call_renders_str_arguments = contains_arg_needle(out);
|
||||||
out = try_raw_render(json::array({
|
out = try_raw_render(json::array({
|
||||||
dummy_user_msg,
|
dummy_user_msg,
|
||||||
make_tool_calls_msg(json::array({make_tool_call("ipython", dummy_args_obj)})),
|
make_tool_calls_msg(json::array({make_tool_call("ipython", dummy_args_obj)})),
|
||||||
}), {}, false);
|
}), {}, false);
|
||||||
auto tool_call_renders_obj_arguments = contains(out, "<parameter=argument_needle>") || contains(out, "\"argument_needle\":") || contains(out, "'argument_needle':");
|
auto tool_call_renders_obj_arguments = contains_arg_needle(out);
|
||||||
|
|
||||||
caps_.supports_tool_calls = tool_call_renders_str_arguments || tool_call_renders_obj_arguments;
|
caps_.supports_tool_calls = tool_call_renders_str_arguments || tool_call_renders_obj_arguments;
|
||||||
caps_.requires_object_arguments = !tool_call_renders_str_arguments && tool_call_renders_obj_arguments;
|
caps_.requires_object_arguments = !tool_call_renders_str_arguments && tool_call_renders_obj_arguments;
|
||||||
|
|||||||
12
vendor/minja/minja.hpp
vendored
12
vendor/minja/minja.hpp
vendored
@@ -2205,7 +2205,7 @@ private:
|
|||||||
|
|
||||||
auto value = parseValue();
|
auto value = parseValue();
|
||||||
|
|
||||||
while (it != end && consumeSpaces() && peekSymbols({ "[", "." })) {
|
while (it != end && consumeSpaces() && peekSymbols({ "[", ".", "(" })) {
|
||||||
if (!consumeToken("[").empty()) {
|
if (!consumeToken("[").empty()) {
|
||||||
std::shared_ptr<Expression> index;
|
std::shared_ptr<Expression> index;
|
||||||
auto slice_loc = get_location();
|
auto slice_loc = get_location();
|
||||||
@@ -2250,15 +2250,13 @@ private:
|
|||||||
auto key = std::make_shared<LiteralExpr>(identifier->location, Value(identifier->get_name()));
|
auto key = std::make_shared<LiteralExpr>(identifier->location, Value(identifier->get_name()));
|
||||||
value = std::make_shared<SubscriptExpr>(identifier->location, std::move(value), std::move(key));
|
value = std::make_shared<SubscriptExpr>(identifier->location, std::move(value), std::move(key));
|
||||||
}
|
}
|
||||||
|
} else if (peekSymbols({ "(" })) {
|
||||||
|
auto callParams = parseCallArgs();
|
||||||
|
value = std::make_shared<CallExpr>(get_location(), std::move(value), std::move(callParams));
|
||||||
}
|
}
|
||||||
consumeSpaces();
|
consumeSpaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peekSymbols({ "(" })) {
|
|
||||||
auto location = get_location();
|
|
||||||
auto callParams = parseCallArgs();
|
|
||||||
value = std::make_shared<CallExpr>(location, std::move(value), std::move(callParams));
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2738,7 +2736,7 @@ inline std::shared_ptr<Context> Context::builtins() {
|
|||||||
globals.set("raise_exception", simple_function("raise_exception", { "message" }, [](const std::shared_ptr<Context> &, Value & args) -> Value {
|
globals.set("raise_exception", simple_function("raise_exception", { "message" }, [](const std::shared_ptr<Context> &, Value & args) -> Value {
|
||||||
throw std::runtime_error(args.at("message").get<std::string>());
|
throw std::runtime_error(args.at("message").get<std::string>());
|
||||||
}));
|
}));
|
||||||
globals.set("tojson", simple_function("tojson", { "value", "indent" }, [](const std::shared_ptr<Context> &, Value & args) {
|
globals.set("tojson", simple_function("tojson", { "value", "indent", "ensure_ascii" }, [](const std::shared_ptr<Context> &, Value & args) {
|
||||||
return Value(args.at("value").dump(args.get<int64_t>("indent", -1), /* to_json= */ true));
|
return Value(args.at("value").dump(args.get<int64_t>("indent", -1), /* to_json= */ true));
|
||||||
}));
|
}));
|
||||||
globals.set("items", simple_function("items", { "object" }, [](const std::shared_ptr<Context> &, Value & args) {
|
globals.set("items", simple_function("items", { "object" }, [](const std::shared_ptr<Context> &, Value & args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user