Upload tokenizer
Browse files- chat_template.jinja +87 -0
- tokenizer.json +2 -2
- tokenizer_config.json +0 -1
chat_template.jinja
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if messages[0]["role"] == "system" %}
|
| 2 |
+
{%- set system_message = messages[0]["content"] %}
|
| 3 |
+
{%- set loop_messages = messages[1:] %}
|
| 4 |
+
{%- else %}
|
| 5 |
+
{%- set loop_messages = messages %}
|
| 6 |
+
{%- endif %}
|
| 7 |
+
{%- if not tools is defined %}
|
| 8 |
+
{%- set tools = none %}
|
| 9 |
+
{%- endif %}
|
| 10 |
+
{%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
|
| 11 |
+
|
| 12 |
+
{#- This block checks for alternating user/assistant messages, skipping tool calling messages #}
|
| 13 |
+
{%- set ns = namespace() %}
|
| 14 |
+
{%- set ns.index = 0 %}
|
| 15 |
+
{%- for message in loop_messages %}
|
| 16 |
+
{%- if not (message.role == "tool" or message.role == "tool_results" or (message.tool_calls is defined and message.tool_calls is not none)) %}
|
| 17 |
+
{%- if (message["role"] == "user") != (ns.index % 2 == 0) %}
|
| 18 |
+
{{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- set ns.index = ns.index + 1 %}
|
| 21 |
+
{%- endif %}
|
| 22 |
+
{%- endfor %}
|
| 23 |
+
|
| 24 |
+
{{- bos_token }}
|
| 25 |
+
{%- for message in loop_messages %}
|
| 26 |
+
{%- if message["role"] == "user" %}
|
| 27 |
+
{%- if tools is not none and (message == user_messages[-1]) %}
|
| 28 |
+
{{- "[AVAILABLE_TOOLS][" }}
|
| 29 |
+
{%- for tool in tools %}
|
| 30 |
+
{%- set tool = tool.function %}
|
| 31 |
+
{{- '{"type": "function", "function": {' }}
|
| 32 |
+
{%- for key, val in tool.items() if key != "return" %}
|
| 33 |
+
{%- if val is string %}
|
| 34 |
+
{{- '"' + key + '": "' + val + '"' }}
|
| 35 |
+
{%- else %}
|
| 36 |
+
{{- '"' + key + '": ' + val|tojson }}
|
| 37 |
+
{%- endif %}
|
| 38 |
+
{%- if not loop.last %}
|
| 39 |
+
{{- ", " }}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endfor %}
|
| 42 |
+
{{- "}}" }}
|
| 43 |
+
{%- if not loop.last %}
|
| 44 |
+
{{- ", " }}
|
| 45 |
+
{%- else %}
|
| 46 |
+
{{- "]" }}
|
| 47 |
+
{%- endif %}
|
| 48 |
+
{%- endfor %}
|
| 49 |
+
{{- "[/AVAILABLE_TOOLS]" }}
|
| 50 |
+
{%- endif %}
|
| 51 |
+
{%- if loop.last and system_message is defined %}
|
| 52 |
+
{{- "[INST]" + system_message + "\n\n" + message["content"] + "[/INST]" }}
|
| 53 |
+
{%- else %}
|
| 54 |
+
{{- "[INST]" + message["content"] + "[/INST]" }}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{%- elif (message.tool_calls is defined and message.tool_calls is not none) %}
|
| 57 |
+
{{- "[TOOL_CALLS][" }}
|
| 58 |
+
{%- for tool_call in message.tool_calls %}
|
| 59 |
+
{%- set out = tool_call.function|tojson %}
|
| 60 |
+
{{- out[:-1] }}
|
| 61 |
+
{%- if not tool_call.id is defined or tool_call.id|length != 9 %}
|
| 62 |
+
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
|
| 63 |
+
{%- endif %}
|
| 64 |
+
{{- ', "id": "' + tool_call.id + '"}' }}
|
| 65 |
+
{%- if not loop.last %}
|
| 66 |
+
{{- ", " }}
|
| 67 |
+
{%- else %}
|
| 68 |
+
{{- "]" + eos_token }}
|
| 69 |
+
{%- endif %}
|
| 70 |
+
{%- endfor %}
|
| 71 |
+
{%- elif message["role"] == "assistant" %}
|
| 72 |
+
{{- message["content"] + eos_token}}
|
| 73 |
+
{%- elif message["role"] == "tool_results" or message["role"] == "tool" %}
|
| 74 |
+
{%- if message.content is defined and message.content.content is defined %}
|
| 75 |
+
{%- set content = message.content.content %}
|
| 76 |
+
{%- else %}
|
| 77 |
+
{%- set content = message.content %}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{{- '[TOOL_RESULTS]{"content": ' + content|string + ", " }}
|
| 80 |
+
{%- if not message.tool_call_id is defined or message.tool_call_id|length != 9 %}
|
| 81 |
+
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
|
| 82 |
+
{%- endif %}
|
| 83 |
+
{{- '"call_id": "' + message.tool_call_id + '"}[/TOOL_RESULTS]' }}
|
| 84 |
+
{%- else %}
|
| 85 |
+
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{%- endfor %}
|
tokenizer.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b142b41ed26fc6f422e0938e42f00f8a5ea81b21d6ad6d27565fc2bdbbc536a7
|
| 3 |
+
size 17078235
|
tokenizer_config.json
CHANGED
|
@@ -8005,7 +8005,6 @@
|
|
| 8005 |
}
|
| 8006 |
},
|
| 8007 |
"bos_token": "<s>",
|
| 8008 |
-
"chat_template": "{%- if messages[0][\"role\"] == \"system\" %}\n {%- set system_message = messages[0][\"content\"] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set loop_messages = messages %}\n{%- endif %}\n{%- if not tools is defined %}\n {%- set tools = none %}\n{%- endif %}\n{%- set user_messages = loop_messages | selectattr(\"role\", \"equalto\", \"user\") | list %}\n\n{#- This block checks for alternating user/assistant messages, skipping tool calling messages #}\n{%- set ns = namespace() %}\n{%- set ns.index = 0 %}\n{%- for message in loop_messages %}\n {%- if not (message.role == \"tool\" or message.role == \"tool_results\" or (message.tool_calls is defined and message.tool_calls is not none)) %}\n {%- if (message[\"role\"] == \"user\") != (ns.index % 2 == 0) %}\n {{- raise_exception(\"After the optional system message, conversation roles must alternate user/assistant/user/assistant/...\") }}\n {%- endif %}\n {%- set ns.index = ns.index + 1 %}\n {%- endif %}\n{%- endfor %}\n\n{{- bos_token }}\n{%- for message in loop_messages %}\n {%- if message[\"role\"] == \"user\" %}\n {%- if tools is not none and (message == user_messages[-1]) %}\n {{- \"[AVAILABLE_TOOLS][\" }}\n {%- for tool in tools %}\n {%- set tool = tool.function %}\n {{- '{\"type\": \"function\", \"function\": {' }}\n {%- for key, val in tool.items() if key != \"return\" %}\n {%- if val is string %}\n {{- '\"' + key + '\": \"' + val + '\"' }}\n {%- else %}\n {{- '\"' + key + '\": ' + val|tojson }}\n {%- endif %}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- endif %}\n {%- endfor %}\n {{- \"}}\" }}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- else %}\n {{- \"]\" }}\n {%- endif %}\n {%- endfor %}\n {{- \"[/AVAILABLE_TOOLS]\" }}\n {%- endif %}\n {%- if loop.last and system_message is defined %}\n {{- \"[INST]\" + system_message + \"\\n\\n\" + message[\"content\"] + \"[/INST]\" }}\n {%- else %}\n {{- \"[INST]\" + message[\"content\"] + \"[/INST]\" }}\n {%- endif %}\n {%- elif (message.tool_calls is defined and message.tool_calls is not none) %}\n {{- \"[TOOL_CALLS][\" }}\n {%- for tool_call in message.tool_calls %}\n {%- set out = tool_call.function|tojson %}\n {{- out[:-1] }}\n {%- if not tool_call.id is defined or tool_call.id|length != 9 %}\n {{- raise_exception(\"Tool call IDs should be alphanumeric strings with length 9!\") }}\n {%- endif %}\n {{- ', \"id\": \"' + tool_call.id + '\"}' }}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- else %}\n {{- \"]\" + eos_token }}\n {%- endif %}\n {%- endfor %}\n {%- elif message[\"role\"] == \"assistant\" %}\n {{- message[\"content\"] + eos_token}}\n {%- elif message[\"role\"] == \"tool_results\" or message[\"role\"] == \"tool\" %}\n {%- if message.content is defined and message.content.content is defined %}\n {%- set content = message.content.content %}\n {%- else %}\n {%- set content = message.content %}\n {%- endif %}\n {{- '[TOOL_RESULTS]{\"content\": ' + content|string + \", \" }}\n {%- if not message.tool_call_id is defined or message.tool_call_id|length != 9 %}\n {{- raise_exception(\"Tool call IDs should be alphanumeric strings with length 9!\") }}\n {%- endif %}\n {{- '\"call_id\": \"' + message.tool_call_id + '\"}[/TOOL_RESULTS]' }}\n {%- else %}\n {{- raise_exception(\"Only user and assistant roles are supported, with the exception of an initial optional system message!\") }}\n {%- endif %}\n{%- endfor %}\n",
|
| 8009 |
"clean_up_tokenization_spaces": false,
|
| 8010 |
"eos_token": "</s>",
|
| 8011 |
"extra_special_tokens": {},
|
|
|
|
| 8005 |
}
|
| 8006 |
},
|
| 8007 |
"bos_token": "<s>",
|
|
|
|
| 8008 |
"clean_up_tokenization_spaces": false,
|
| 8009 |
"eos_token": "</s>",
|
| 8010 |
"extra_special_tokens": {},
|