Upload folder using huggingface_hub
Browse files- chat_template.jinja +77 -14
chat_template.jinja
CHANGED
|
@@ -1,14 +1,77 @@
|
|
| 1 |
-
{
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if not add_generation_prompt is defined -%}
|
| 2 |
+
{%- set add_generation_prompt = false -%}
|
| 3 |
+
{%- endif -%}
|
| 4 |
+
{%- set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt="", is_first_sp=true, is_last_user=false) -%}
|
| 5 |
+
{%- for message in messages -%}
|
| 6 |
+
{%- if message["role"] == "system" -%}
|
| 7 |
+
{%- if ns.is_first_sp -%}
|
| 8 |
+
{%- set ns.system_prompt = ns.system_prompt + message["content"] -%}
|
| 9 |
+
{%- set ns.is_first_sp = false -%}
|
| 10 |
+
{%- else -%}
|
| 11 |
+
{%- set ns.system_prompt = ns.system_prompt + "\n\n" + message["content"] -%}
|
| 12 |
+
{%- endif -%}
|
| 13 |
+
{%- endif -%}
|
| 14 |
+
{%- endfor -%}
|
| 15 |
+
{{- bos_token -}}
|
| 16 |
+
{{- ns.system_prompt -}}
|
| 17 |
+
{%- for message in messages -%}
|
| 18 |
+
{%- set content = message["content"] -%}
|
| 19 |
+
{%- if message["role"] == "user" -%}
|
| 20 |
+
{%- set ns.is_tool = false -%}
|
| 21 |
+
{%- set ns.is_first = false -%}
|
| 22 |
+
{%- set ns.is_last_user = true -%}
|
| 23 |
+
{{- "<|User|>" + content + "<|Assistant|>" -}}
|
| 24 |
+
{%- endif -%}
|
| 25 |
+
{%- if message["role"] == "assistant" -%}
|
| 26 |
+
{%- if "</think>" in content -%}
|
| 27 |
+
{%- set content = content.split("</think>")[-1] -%}
|
| 28 |
+
{%- endif -%}
|
| 29 |
+
{%- endif -%}
|
| 30 |
+
{%- if message["role"] == "assistant" and message["tool_calls"] is defined and message["tool_calls"] is not none -%}
|
| 31 |
+
{%- set ns.is_last_user = false -%}
|
| 32 |
+
{%- if ns.is_tool -%}
|
| 33 |
+
{{- "<|tool▁outputs▁end|>" -}}
|
| 34 |
+
{%- endif -%}
|
| 35 |
+
{%- set ns.is_first = false -%}
|
| 36 |
+
{%- set ns.is_tool = false -%}
|
| 37 |
+
{%- set ns.is_output_first = true -%}
|
| 38 |
+
{%- for tool in message["tool_calls"] -%}
|
| 39 |
+
{%- if not ns.is_first -%}
|
| 40 |
+
{%- if content is none -%}
|
| 41 |
+
{{- "<|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
|
| 42 |
+
{%- else -%}
|
| 43 |
+
{{- content + "<|tool▁calls▁begin|><|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
|
| 44 |
+
{%- endif -%}
|
| 45 |
+
{%- set ns.is_first = true -%}
|
| 46 |
+
{%- else -%}
|
| 47 |
+
{{- "\n" + "<|tool▁call▁begin|>" + tool["type"] + "<|tool▁sep|>" + tool["function"]["name"] + "\n" + "```json" + "\n" + tool["function"]["arguments"] + "\n" + "```" + "<|tool▁call▁end|>" -}}
|
| 48 |
+
{%- endif -%}
|
| 49 |
+
{%- endfor -%}
|
| 50 |
+
{{- "<|tool▁calls▁end|><|end▁of▁sentence|>" -}}
|
| 51 |
+
{%- endif -%}
|
| 52 |
+
{%- if message["role"] == "assistant" and (message["tool_calls"] is not defined or message["tool_calls"] is none) -%}
|
| 53 |
+
{%- set ns.is_last_user = false -%}
|
| 54 |
+
{%- if ns.is_tool -%}
|
| 55 |
+
{{- "<|tool▁outputs▁end|>" + content + "<|end▁of▁sentence|>" -}}
|
| 56 |
+
{%- set ns.is_tool = false -%}
|
| 57 |
+
{%- else -%}
|
| 58 |
+
{{- content + "<|end▁of▁sentence|>" -}}
|
| 59 |
+
{%- endif -%}
|
| 60 |
+
{%- endif -%}
|
| 61 |
+
{%- if message["role"] == "tool" -%}
|
| 62 |
+
{%- set ns.is_last_user = false -%}
|
| 63 |
+
{%- set ns.is_tool = true -%}
|
| 64 |
+
{%- if ns.is_output_first -%}
|
| 65 |
+
{{- "<|tool▁outputs▁begin|><|tool▁output▁begin|>" + content + "<|tool▁output▁end|>" -}}
|
| 66 |
+
{%- set ns.is_output_first = false -%}
|
| 67 |
+
{%- else -%}
|
| 68 |
+
{{- "\n<|tool▁output▁begin|>" + content + "<|tool▁output▁end|>" -}}
|
| 69 |
+
{%- endif -%}
|
| 70 |
+
{%- endif -%}
|
| 71 |
+
{%- endfor -%}
|
| 72 |
+
{%- if ns.is_tool -%}
|
| 73 |
+
{{- "<|tool▁outputs▁end|>" -}}
|
| 74 |
+
{%- endif -%}
|
| 75 |
+
{%- if add_generation_prompt and not ns.is_last_user and not ns.is_tool -%}
|
| 76 |
+
{{- "<|Assistant|>" -}}
|
| 77 |
+
{%- endif -%}
|