Repository: ggerganov/llama.cpp
File: common/jinja/value.cpp (C++)

Code before:
        {"join", [](const func_args &) -> value {
            throw not_implemented_exception("object join not implemented");
        }},
    };
    return builtins;
}

const func_builtins & value_none_t::get_builtins() const {
    static const func_builtins builtins = {
        {"default", default_value},
        {"tojson", tojson},
        {"string", [](const func_args &) -> value {
            return mk_val<value_string>("None");
        }},
        {"safe", [](const func_args &) -> value {
            return mk_val<value_string>("None");
        }},
    };
    return builtins;
}


const func_builtins & value_undefined_t::get_builtins() const {
    static const func_builtins builtins = {
        {"default", default_value},
        {"capitalize", [](const func_args &) -> value {
            return mk_val<value_string>();
        }},
        {"first", [](const func_args &) -> value {
            return mk_val<value_string>();
        }},
        {"items", [](const func_args &) -> value {
            return mk_val<value_array>();
        }},
        {"join", [](const func_args &) -> value {
            return mk_val<value_string>();
        }},
        {"last", [](const func_args &) -> value {
            return mk_val<value_string>();
        }},
        {"length", [](const func_args &) -> value {
            return mk_val<value_int>(0);
        }},
        {"list", [](const func_args &) -> value {
            return mk_val<value_array>();
        }},
        {"lower", [](const func_args &) -> value {
            return mk_val<value_string>();
        }},
        {"map", [](const func_args &) -> value {
            return mk_val<value_array>();

Review comment (suggestion):
we can also define each function once, then use map it here to make the code more concise. example:

```cpp
static const auto make_str = [](const func_args &) -> value { return mk_val<value_string>(); }
...
{"capitalize", make_str},
{"first", make_str},
```

Code after:
        {"dictsort", [](const func_args & args) -> value {
            value val_input   = args.get_pos(0);
            value val_case    = args.get_kwarg_or_pos("case_sensitive", 1);
            value val_by      = args.get_kwarg_or_pos("by",             2);
            value val_reverse = args.get_kwarg_or_pos("reverse",        3);
            // FIXME: sorting is currently always case sensitive
            //const bool case_sensitive = val_case->as_bool(); // undefined == false
            const bool reverse = val_reverse->as_bool(); // undefined == false
            const bool by_value = is_val<value_string>(val_by) && val_by->as_string().str() == "value" ? true : false;
            auto result = mk_val<value_object>(val_input); // copy
            std::sort(result->val_obj.begin(), result->val_obj.end(), [&](const auto & a, const auto & b) {
                if (by_value) {
                    return value_compare(a.second, b.second, reverse ? value_compare_op::gt : value_compare_op::lt);
                } else {
                    return value_compare(a.first, b.first, reverse ? value_compare_op::gt : value_compare_op::lt);
                }
            });
            return result;
        }},
        {"join", [](const func_args &) -> value {
            throw not_implemented_exception("object join not implemented");
        }},
    };
    return builtins;
}

const func_builtins & value_none_t::get_builtins() const {
    static const func_builtins builtins = {
        {"default", default_value},
        {"tojson", tojson},
        {"string", [](const func_args &) -> value {
            return mk_val<value_string>("None");
        }},
        {"safe", [](const func_args &) -> value {
            return mk_val<value_string>("None");
        }},
    };
    return builtins;
}


const func_builtins & value_undefined_t::get_builtins() const {
    static const func_builtins builtins = {
        {"default", default_value},
        {"capitalize", empty_value_fn<value_string>},
        {"first", empty_value_fn<value_undefined>},
        {"items", empty_value_fn<value_array>},
        {"join", empty_value_fn<value_string>},
        {"last", empty_value_fn<value_undefined>},
        {"length", empty_value_fn<value_int>},
        {"list", empty_value_fn<value_array>},