chat templates: work around Jinja2Cpp issue with 'not X is defined' (#3372)

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Signed-off-by: AT <manyoso@users.noreply.github.com>
Co-authored-by: AT <manyoso@users.noreply.github.com>
This commit is contained in:
Jared Van Bortel
2025-01-07 18:00:10 -05:00
committed by GitHub
parent e2541a24b3
commit a0abc93701
3 changed files with 8 additions and 22 deletions

View File

@@ -203,13 +203,7 @@ const std::unordered_map<std::string_view, std::string_view> CHAT_TEMPLATE_SUBST
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
{%- endif %})TEMPLATE",
R"TEMPLATE({{- bos_token }}
{%- if not date_string is defined %}
{%- if strftime_now is defined %}
{%- set date_string = strftime_now('%d %b %Y') %}
{%- else %}
{%- set date_string = '26 Jul 2024' %}
{%- endif %}
{%- endif %}
{%- set date_string = strftime_now('%d %b %Y') %}
{#- This block extracts the system message, so we can slot it into the right place. #}
{%- if messages[0]['role'] == 'system' %}
@@ -348,13 +342,7 @@ const std::unordered_map<std::string_view, std::string_view> CHAT_TEMPLATE_SUBST
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
{%- endif %})TEMPLATE",
R"TEMPLATE({{- bos_token }}
{%- if not date_string is defined %}
{%- if strftime_now is defined %}
{%- set date_string = strftime_now("%d %b %Y") %}
{%- else %}
{%- set date_string = "26 Jul 2024" %}
{%- endif %}
{%- endif %}
{%- set date_string = strftime_now("%d %b %Y") %}
{#- This block extracts the system message, so we can slot it into the right place. #}
{%- if messages[0]['role'] == 'system' %}
@@ -420,10 +408,7 @@ const std::unordered_map<std::string_view, std::string_view> CHAT_TEMPLATE_SUBST
' + message['content'] + '<|im_end|>' + '
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %})TEMPLATE",
R"TEMPLATE({%- if not add_generation_prompt is defined %}
{%- set add_generation_prompt = false %}
{%- endif %}
{%- for message in messages %}
R"TEMPLATE({%- for message in messages %}
{{- '<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n' }}
{%- endfor %}
{%- if add_generation_prompt %}