From f4ae0075e8f2b8518f57888bdddedebf88793814 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:16:52 -0800 Subject: [PATCH] Fix conversion from old template format to jinja2 --- modules/chat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chat.py b/modules/chat.py index 3106d3d2..973a7fbd 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -768,13 +768,13 @@ def delete_character(name, instruct=False): def jinja_template_from_old_format(params, verbose=False): MASTER_TEMPLATE = """ -{%- set found_item = false -%} +{%- set ns = namespace(found=false) -%} {%- for message in messages -%} {%- if message['role'] == 'system' -%} - {%- set found_item = true -%} + {%- set ns.found = true -%} {%- endif -%} {%- endfor -%} -{%- if not found_item -%} +{%- if not ns.found -%} {{- '<|PRE-SYSTEM|>' + '<|SYSTEM-MESSAGE|>' + '<|POST-SYSTEM|>' -}} {%- endif %} {%- for message in messages %}