diff --git a/common/templating.py b/common/templating.py index 1200e5c..2134942 100644 --- a/common/templating.py +++ b/common/templating.py @@ -10,6 +10,8 @@ from jinja2.sandbox import ImmutableSandboxedEnvironment from loguru import logger from packaging import version +from datetime import datetime + from common.utils import unwrap @@ -95,10 +97,16 @@ async def render(self, template_vars: dict): def compile(self, template_str: str): """Compiles and stores a jinja2 template""" + # Some models require strftime_now, e.g. Granite3 + def strftime_now(format): + current_time = datetime.now() + return current_time.strftime(format) + # Exception handler def raise_exception(message): raise TemplateError(message) + self.environment.globals["strftime_now"] = strftime_now self.environment.globals["raise_exception"] = raise_exception return self.environment.from_string(template_str)