From 73fc5c476755f7a82ee509bfa39cef125eb8685b Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Sun, 8 Mar 2026 12:12:02 +0800 Subject: [PATCH] handle jinja exceptions --- koboldcpp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/koboldcpp.py b/koboldcpp.py index e6eddca97..708a2d943 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -2655,6 +2655,9 @@ def format_jinja(messages, tools): return datetime.now().strftime(format) def tojson(x, ensure_ascii=False, indent=None, separators=None, sort_keys=False): return json.dumps(x, ensure_ascii=ensure_ascii, indent=indent, separators=separators, sort_keys=sort_keys) + def raise_exception(msg): + print(f"Warning: Jinja template raised an exception: {msg}") + return "" global cached_chat_template from jinja2.sandbox import ImmutableSandboxedEnvironment jinja_env = ImmutableSandboxedEnvironment(trim_blocks=True, lstrip_blocks=True) @@ -2663,6 +2666,7 @@ def format_jinja(messages, tools): if m.get("content") is None: del m["content"] jinja_env.globals['strftime_now'] = strftime_now + jinja_env.globals['raise_exception'] = raise_exception jinja_env.filters["tojson"] = tojson jinja_compiled_template = jinja_env.from_string(cached_chat_template) text = None