Fix conversion from old template format to jinja2

This commit is contained in:
oobabooga 2023-12-19 13:16:52 -08:00
parent de138b8ba6
commit f4ae0075e8

View File

@ -768,13 +768,13 @@ def delete_character(name, instruct=False):
def jinja_template_from_old_format(params, verbose=False): def jinja_template_from_old_format(params, verbose=False):
MASTER_TEMPLATE = """ MASTER_TEMPLATE = """
{%- set found_item = false -%} {%- set ns = namespace(found=false) -%}
{%- for message in messages -%} {%- for message in messages -%}
{%- if message['role'] == 'system' -%} {%- if message['role'] == 'system' -%}
{%- set found_item = true -%} {%- set ns.found = true -%}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- if not found_item -%} {%- if not ns.found -%}
{{- '<|PRE-SYSTEM|>' + '<|SYSTEM-MESSAGE|>' + '<|POST-SYSTEM|>' -}} {{- '<|PRE-SYSTEM|>' + '<|SYSTEM-MESSAGE|>' + '<|POST-SYSTEM|>' -}}
{%- endif %} {%- endif %}
{%- for message in messages %} {%- for message in messages %}