]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
jinja: support none|string (#18995)
authorPiotr Wilkin (ilintar) <redacted>
Wed, 21 Jan 2026 18:24:37 +0000 (19:24 +0100)
committerGitHub <redacted>
Wed, 21 Jan 2026 18:24:37 +0000 (19:24 +0100)
* jinja: support none|string

* Update common/jinja/value.cpp

Co-authored-by: Sigbjørn Skjæret <redacted>
* Update tests/test-jinja.cpp

Co-authored-by: Sigbjørn Skjæret <redacted>
* Add as_string()

---------

Co-authored-by: Sigbjørn Skjæret <redacted>
common/jinja/value.cpp
common/jinja/value.h
tests/test-jinja.cpp

index e414aad444cab9f8b49411ea250d512871075098..d2ed8242699c01fda4ca8391ba34cbdf71be2dc5 100644 (file)
@@ -1005,6 +1005,7 @@ 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"); }}
     };
     return builtins;
 }
index 7bd0202cea88f700099af668a4d275f22d195344..ccb05c6fd413befbc3eb3d6a4768e06e324299b4 100644 (file)
@@ -342,12 +342,12 @@ struct value_none_t : public value_t {
     virtual std::string type() const override { return "None"; }
     virtual bool is_none() const override { return true; }
     virtual bool as_bool() const override { return false; }
+    virtual string as_string() const override { return string("None"); }
     virtual std::string as_repr() const override { return type(); }
     virtual const func_builtins & get_builtins() const override;
 };
 using value_none = std::shared_ptr<value_none_t>;
 
-
 struct value_undefined_t : public value_t {
     std::string hint; // for debugging, to indicate where undefined came from
     value_undefined_t(const std::string & h = "") : hint(h) {}
index 99630ecb3b8c1f881af41741711e29be1ff11a40..54d3a0923bdf7bdab85ca7c52d33585147348915 100644 (file)
@@ -609,6 +609,12 @@ static void test_filters(testing & t) {
         json::object(),
         "hello"
     );
+
+    test_template(t, "none to string",
+        "{{ x|string }}",
+        {{"x", nullptr}},
+        "None"
+    );
 }
 
 static void test_literals(testing & t) {