Skip to content

Commit 8347da9

Browse files
author
ochafik
committed
Update minja to google/minja@b8437df
1 parent 8a7c89e commit 8347da9

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

common/chat-template.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class chat_template {
113113
}
114114

115115
const std::string & source() const { return source_; }
116+
const std::string & bos_token() const { return bos_token_; }
117+
const std::string & eos_token() const { return eos_token_; }
116118
bool supports_tools() const { return supports_tools_; }
117119
bool supports_parallel_tool_calls() const { return supports_parallel_tool_calls_; }
118120

common/minja.hpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,11 @@ class Value : public std::enable_shared_from_this<Value> {
366366
throw std::runtime_error("contains can only be called on arrays and objects: " + dump());
367367
}
368368
}
369-
void erase(size_t index) {
370-
if (array_) throw std::runtime_error("Value is not an array: " + dump());
369+
Value pop(size_t index) {
370+
if (!array_) throw std::runtime_error("Value is not an array: " + dump());
371+
auto value = array_->at(index);
371372
array_->erase(array_->begin() + index);
372-
}
373-
void erase(const std::string & key) {
374-
if (object_) throw std::runtime_error("Value is not an object: " + dump());
375-
object_->erase(key);
373+
return value;
376374
}
377375
const Value& at(const Value & index) const {
378376
return const_cast<Value*>(this)->at(index);
@@ -1353,6 +1351,15 @@ class MethodCallExpr : public Expression {
13531351
if (index < 0 || index > (int64_t) obj.size()) throw std::runtime_error("Index out of range for insert method");
13541352
obj.insert(index, vargs.args[1]);
13551353
return Value();
1354+
} else if (method->get_name() == "pop") {
1355+
vargs.expectArgs("pop method", {0, 1}, {0, 0});
1356+
if (vargs.args.empty()) {
1357+
return obj.pop(obj.size() - 1);
1358+
} else {
1359+
auto index = vargs.args[0].get<int64_t>();
1360+
if (index < 0 || index >= (int64_t) obj.size()) throw std::runtime_error("Index out of range for pop method");
1361+
return obj.pop(index);
1362+
}
13561363
}
13571364
} else if (obj.is_object()) {
13581365
if (method->get_name() == "items") {
@@ -2539,7 +2546,7 @@ inline std::shared_ptr<Context> Context::builtins() {
25392546
}));
25402547
globals.set("namespace", Value::callable([=](const std::shared_ptr<Context> &, ArgumentsValue & args) {
25412548
auto ns = Value::object();
2542-
args.expectArgs("namespace", {0, 0}, {0, (std::numeric_limits<size_t>::max)()});
2549+
args.expectArgs("namespace", {0, 0}, {0, std::numeric_limits<size_t>::max()});
25432550
for (auto & [name, value] : args.kwargs) {
25442551
ns.set(name, value);
25452552
}
@@ -2594,7 +2601,7 @@ inline std::shared_ptr<Context> Context::builtins() {
25942601
};
25952602
// https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.reject
25962603
globals.set("reject", Value::callable([=](const std::shared_ptr<Context> & context, ArgumentsValue & args) {
2597-
args.expectArgs("reject", {2, (std::numeric_limits<size_t>::max)()}, {0, 0});
2604+
args.expectArgs("reject", {2, std::numeric_limits<size_t>::max()}, {0, 0});
25982605
auto & items = args.args[0];
25992606
auto filter_fn = context->get(args.args[1]);
26002607
if (filter_fn.is_null()) throw std::runtime_error("Undefined filter: " + args.args[1].dump());
@@ -2665,7 +2672,7 @@ inline std::shared_ptr<Context> Context::builtins() {
26652672
return out;
26662673
}));
26672674
globals.set("selectattr", Value::callable([=](const std::shared_ptr<Context> & context, ArgumentsValue & args) {
2668-
args.expectArgs("selectattr", {2, (std::numeric_limits<size_t>::max)()}, {0, 0});
2675+
args.expectArgs("selectattr", {2, std::numeric_limits<size_t>::max()}, {0, 0});
26692676
auto & items = args.args[0];
26702677
if (items.is_null())
26712678
return Value::array();

0 commit comments

Comments
 (0)