Upload chat_template.jinja with huggingface_hub
Browse files- chat_template.jinja +61 -0
chat_template.jinja
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if not add_generation_prompt is defined -%}
|
| 2 |
+
{%- set add_generation_prompt = false -%}
|
| 3 |
+
{%- endif -%}
|
| 4 |
+
{%- if not thinking is defined -%}
|
| 5 |
+
{%- if enable_thinking is defined -%}
|
| 6 |
+
{%- set thinking = enable_thinking -%}
|
| 7 |
+
{%- else -%}
|
| 8 |
+
{%- set thinking = false -%}
|
| 9 |
+
{%- endif -%}
|
| 10 |
+
{%- endif -%}
|
| 11 |
+
{%- set ns = namespace(system_prompt='', is_first_sp=true, is_last_user=false, is_only_sys=false, is_prefix=false) -%}
|
| 12 |
+
{%- for message in messages -%}
|
| 13 |
+
{%- if message['role'] == 'system' -%}
|
| 14 |
+
{%- if ns.is_first_sp -%}
|
| 15 |
+
{%- set ns.system_prompt = ns.system_prompt + message['content'] -%}
|
| 16 |
+
{%- set ns.is_first_sp = false -%}
|
| 17 |
+
{%- else -%}
|
| 18 |
+
{%- set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] -%}
|
| 19 |
+
{%- endif -%}
|
| 20 |
+
{%- set ns.is_only_sys = true -%}
|
| 21 |
+
{%- endif -%}
|
| 22 |
+
{%- endfor -%}
|
| 23 |
+
{{- bos_token -}}{{- ns.system_prompt -}}
|
| 24 |
+
{%- for message in messages -%}
|
| 25 |
+
{%- if message['role'] == 'user' -%}
|
| 26 |
+
{%- set ns.is_last_user = true -%}
|
| 27 |
+
{{- '<|User|>' + message['content'] -}}
|
| 28 |
+
{%- endif -%}
|
| 29 |
+
{%- if message['role'] == 'assistant' -%}
|
| 30 |
+
{%- if ns.is_last_user -%}
|
| 31 |
+
{{- '<|Assistant|>' -}}
|
| 32 |
+
{%- if message['prefix'] is defined and message['prefix'] and thinking -%}
|
| 33 |
+
{{- '<think>' -}}
|
| 34 |
+
{%- else -%}
|
| 35 |
+
{{- '</think>' -}}
|
| 36 |
+
{%- endif -%}
|
| 37 |
+
{%- endif -%}
|
| 38 |
+
{%- if message['prefix'] is defined and message['prefix'] -%}
|
| 39 |
+
{%- set ns.is_prefix = true -%}
|
| 40 |
+
{%- endif -%}
|
| 41 |
+
{%- set ns.is_last_user = false -%}
|
| 42 |
+
{%- set content = message['content'] -%}
|
| 43 |
+
{%- if '</think>' in content -%}
|
| 44 |
+
{%- set content = content.split('</think>', 1)[1] -%}
|
| 45 |
+
{%- endif -%}
|
| 46 |
+
{{- content + '<|end▁of▁sentence|>' -}}
|
| 47 |
+
{%- endif -%}
|
| 48 |
+
{%- if message['role'] != 'system' -%}
|
| 49 |
+
{%- set ns.is_only_sys = false -%}
|
| 50 |
+
{%- endif -%}
|
| 51 |
+
{%- endfor -%}
|
| 52 |
+
{%- if add_generation_prompt -%}
|
| 53 |
+
{%- if ns.is_last_user or ns.is_only_sys or not ns.is_prefix -%}
|
| 54 |
+
{{- '<|Assistant|>' -}}
|
| 55 |
+
{%- if not thinking -%}
|
| 56 |
+
{{- '</think>' -}}
|
| 57 |
+
{%- else -%}
|
| 58 |
+
{{- '<think>' -}}
|
| 59 |
+
{%- endif -%}
|
| 60 |
+
{%- endif -%}
|
| 61 |
+
{%- endif -%}
|