From 3dd0704b7f9184c264a5cbd62753455c064b7565 Mon Sep 17 00:00:00 2001 From: ThiloteE <73715071+ThiloteE@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:59:19 +0100 Subject: [PATCH] Add trimming whitespace to Qwen2-1.5b-Instruct and Gemma-2-9b-it Based on https://huggingface.co/docs/transformers/main/chat_templating#trimming-whitespace Signed-off-by: ThiloteE <73715071+ThiloteE@users.noreply.github.com> --- .../docs/gpt4all_desktop/chat_templates.md | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/gpt4all-bindings/python/docs/gpt4all_desktop/chat_templates.md b/gpt4all-bindings/python/docs/gpt4all_desktop/chat_templates.md index e6f72456f213..1e4f863a2afd 100644 --- a/gpt4all-bindings/python/docs/gpt4all_desktop/chat_templates.md +++ b/gpt4all-bindings/python/docs/gpt4all_desktop/chat_templates.md @@ -210,37 +210,37 @@ For standard templates, GPT4All combines the user message, sources, and attachme See issue [3282](https://github.com/nomic-ai/gpt4all/issues/3282) ```jinja {{ bos_token }} -{% if messages[0]['role'] == 'system' %} +{%- if messages[0]['role'] == 'system' %} {{ raise_exception('System role not supported') }} -{% endif %} +{%- endif %} -{% for message in messages %} - {% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %} +{%- for message in messages %} + {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %} {{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }} - {% endif %} - {% if (message['role'] == 'assistant') %} - {% set role = 'model' %} - {% else %}{% set role = message['role'] %} - {% endif %} - {{ '' + role + '\n' + message['content'] | trim + '\n' }} -{% endfor %} - -{% if add_generation_prompt %} - {{'model\n' }} -{% endif %} + {%- endif %} + {%- if (message['role'] == 'assistant') %} + {%- set role = 'model' %} + {%- else %}{% set role = message['role'] %} + {%- endif %} + {{- '' + role + '\n' + message['content'] | trim + '\n' }} +{%- endfor %} + +{%- if add_generation_prompt %} + {{ 'model\n' }} +{%- endif %} ``` ## Qwen/Qwen2-1.5B-Instruct See issue [3263](https://github.com/nomic-ai/gpt4all/issues/3263) ```jinja -{% for message in messages %} - {% if loop.first and messages[0]['role'] != 'system' %} - {{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }} - {% endif %} - {{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n' }} -{% endfor %} - -{% if add_generation_prompt %} +{%- for message in messages %} + {%- if loop.first and messages[0]['role'] != 'system' %} + {{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }} + {%- endif %} + {{ '<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n' }} +{%- endfor %} + +{%- if add_generation_prompt %} {{ '<|im_start|>assistant\n' }} -{% endif %} +{%- endif %} ```