Skip to content

Commit 059babd

Browse files
author
ochafik
committed
minja: try to please gcc
1 parent 94377d7 commit 059babd

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

common/minja.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -376,38 +376,6 @@ class Value : public std::enable_shared_from_this<Value> {
376376
throw std::runtime_error("get<T> not defined for this value type: " + dump());
377377
}
378378

379-
template <>
380-
json get<json>() const {
381-
if (is_primitive()) return primitive_;
382-
if (is_null()) return json();
383-
if (array_) {
384-
std::vector<json> res;
385-
for (const auto& item : *array_) {
386-
res.push_back(item.get<json>());
387-
}
388-
return res;
389-
}
390-
if (object_) {
391-
json res = json::object();
392-
for (const auto& item : *object_) {
393-
const auto & key = item.first;
394-
auto json_value = item.second.get<json>();
395-
if (key.is_string()) {
396-
res[key.get<std::string>()] = json_value;
397-
} else if (key.is_primitive()) {
398-
res[key.dump()] = json_value;
399-
} else {
400-
throw std::runtime_error("Invalid key type for conversion to JSON: " + key.dump());
401-
}
402-
}
403-
if (is_callable()) {
404-
res["__callable__"] = true;
405-
}
406-
return res;
407-
}
408-
throw std::runtime_error("get<json> not defined for this value type: " + dump());
409-
}
410-
411379
std::string dump(int indent=-1, bool to_json=false) const {
412380
std::ostringstream out;
413381
dump(out, indent, 0, to_json ? '"' : '\'');
@@ -466,6 +434,38 @@ class Value : public std::enable_shared_from_this<Value> {
466434
}
467435
};
468436

437+
template <>
438+
json Value::get<json>() const {
439+
if (is_primitive()) return primitive_;
440+
if (is_null()) return json();
441+
if (array_) {
442+
std::vector<json> res;
443+
for (const auto& item : *array_) {
444+
res.push_back(item.get<json>());
445+
}
446+
return res;
447+
}
448+
if (object_) {
449+
json res = json::object();
450+
for (const auto& item : *object_) {
451+
const auto & key = item.first;
452+
auto json_value = item.second.get<json>();
453+
if (key.is_string()) {
454+
res[key.get<std::string>()] = json_value;
455+
} else if (key.is_primitive()) {
456+
res[key.dump()] = json_value;
457+
} else {
458+
throw std::runtime_error("Invalid key type for conversion to JSON: " + key.dump());
459+
}
460+
}
461+
if (is_callable()) {
462+
res["__callable__"] = true;
463+
}
464+
return res;
465+
}
466+
throw std::runtime_error("get<json> not defined for this value type: " + dump());
467+
}
468+
469469
} // namespace minja
470470

471471
namespace std {

src/llama.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21081,8 +21081,8 @@ static int32_t llama_chat_apply_template_internal(
2108121081
context->set("tools", tools_val);
2108221082
}
2108321083
auto tmpl_root = minja::Parser::parse(tmpl, {
21084-
.lstrip_blocks = true,
2108521084
.trim_blocks = true,
21085+
.lstrip_blocks = true,
2108621086
});
2108721087
try {
2108821088
dest = tmpl_root->render(context);

0 commit comments

Comments
 (0)