mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-13 12:10:18 +00:00
minja
: don't explode upon referencing a field on an array (fixes Hermes tool use template)
This commit is contained in:
parent
c059aecd37
commit
5789f69d2d
@ -228,6 +228,9 @@ public:
|
|||||||
}
|
}
|
||||||
Value get(const Value& key) {
|
Value get(const Value& key) {
|
||||||
if (array_) {
|
if (array_) {
|
||||||
|
if (!key.is_number_integer()) {
|
||||||
|
return Value();
|
||||||
|
}
|
||||||
auto index = key.get<int>();
|
auto index = key.get<int>();
|
||||||
return array_->at(index < 0 ? array_->size() + index : index);
|
return array_->at(index < 0 ? array_->size() + index : index);
|
||||||
} else if (object_) {
|
} else if (object_) {
|
||||||
@ -618,7 +621,7 @@ public:
|
|||||||
Value evaluate(const std::shared_ptr<Context> & context) const {
|
Value evaluate(const std::shared_ptr<Context> & context) const {
|
||||||
try {
|
try {
|
||||||
return do_evaluate(context);
|
return do_evaluate(context);
|
||||||
} catch (const std::runtime_error & e) {
|
} catch (const std::exception & e) {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << e.what();
|
out << e.what();
|
||||||
if (location.source) out << error_location_suffix(*location.source, location.pos);
|
if (location.source) out << error_location_suffix(*location.source, location.pos);
|
||||||
@ -769,7 +772,7 @@ public:
|
|||||||
void render(std::ostringstream & out, const std::shared_ptr<Context> & context) const {
|
void render(std::ostringstream & out, const std::shared_ptr<Context> & context) const {
|
||||||
try {
|
try {
|
||||||
do_render(out, context);
|
do_render(out, context);
|
||||||
} catch (const std::runtime_error & e) {
|
} catch (const std::exception & e) {
|
||||||
std::ostringstream err;
|
std::ostringstream err;
|
||||||
err << e.what();
|
err << e.what();
|
||||||
if (location_.source) err << error_location_suffix(*location_.source, location_.pos);
|
if (location_.source) err << error_location_suffix(*location_.source, location_.pos);
|
||||||
@ -2152,7 +2155,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tokens;
|
return tokens;
|
||||||
} catch (const std::runtime_error & e) {
|
} catch (const std::exception & e) {
|
||||||
throw std::runtime_error(e.what() + error_location_suffix(*template_str, std::distance(start, it)));
|
throw std::runtime_error(e.what() + error_location_suffix(*template_str, std::distance(start, it)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user