danielhanchen commited on
Commit
fe1d42c
·
verified ·
1 Parent(s): 51d6680

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. chat_template.jinja +8 -3
  2. tokenizer_config.json +1 -1
chat_template.jinja CHANGED
@@ -1,5 +1,8 @@
 
 
 
1
  {# ==================================================================== #}
2
- {# Deepseek v3 template with enable_thinking and tools support #}
3
  {# ==================================================================== #}
4
  {%- if not enable_thinking is defined %}{% set enable_thinking = false %}{% endif -%}
5
  {%- if not tools is defined %}{% set tools = none %}{% endif -%}
@@ -97,7 +100,7 @@ You have the following functions available:
97
  {{- "
98
  " -}}
99
  {%- endif -%}
100
- {%- if loop.nextitem is undefined or loop.nextitem.role != 'tool' -%}
101
  {{- "<|tool▁outputs▁end|>" -}}
102
  {%- set ns.outputs_open = false -%}
103
  {%- endif -%}
@@ -114,4 +117,6 @@ You have the following functions available:
114
 
115
  {%- if add_generation_prompt and enable_thinking -%}
116
  {{- '<think>\n' -}}
117
- {%- endif -%}
 
 
 
1
+ {# Copyright 2025-present the Unsloth team. All rights reserved. #}
2
+ {# Licensed under the Apache License, Version 2.0 (the "License") #}
3
+ {# Edits made by Unsloth to fix the chat template #}
4
  {# ==================================================================== #}
5
+ {# Deepseek v3 template with enable_thinking and tools support #}
6
  {# ==================================================================== #}
7
  {%- if not enable_thinking is defined %}{% set enable_thinking = false %}{% endif -%}
8
  {%- if not tools is defined %}{% set tools = none %}{% endif -%}
 
100
  {{- "
101
  " -}}
102
  {%- endif -%}
103
+ {%- if loop.nextitem is not defined or loop.nextitem.role != 'tool' -%}
104
  {{- "<|tool▁outputs▁end|>" -}}
105
  {%- set ns.outputs_open = false -%}
106
  {%- endif -%}
 
117
 
118
  {%- if add_generation_prompt and enable_thinking -%}
119
  {{- '<think>\n' -}}
120
+ {%- endif -%}
121
+ {# Copyright 2025-present the Unsloth team. All rights reserved. #}
122
+ {# Licensed under the Apache License, Version 2.0 (the "License") #}
tokenizer_config.json CHANGED
@@ -6560,5 +6560,5 @@
6560
  "tokenizer_class": "LlamaTokenizerFast",
6561
  "unk_token": null,
6562
  "use_default_system_prompt": false,
6563
- "chat_template": "{# ==================================================================== #}\n{# Deepseek v3 template with enable_thinking and tools support #}\n{# ==================================================================== #}\n{%- if not enable_thinking is defined %}{% set enable_thinking = false %}{% endif -%}\n{%- if not tools is defined %}{% set tools = none %}{% endif -%}\n{%- if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif -%}\n\n{# --------------------------- Collect system prompt -------------------- #}\n{%- set ns = namespace(system_prompt='', is_last_user=false, outputs_open=false, first_output=true) -%}\n\n{%- if messages and messages[0].role == 'system' -%}\n {%- set raw = messages[0].content -%}\n {%- set ns.system_prompt = raw if raw is string else raw[0].text -%}\n {%- set messages = messages[1:] -%}\n{%- endif -%}\n\n{# --------------------------- Inject deep thinking --------------------- #}\n{%- if enable_thinking -%}\n {%- set ns.system_prompt = ns.system_prompt and 'Enable deep thinking subroutine.\n\n' ~ ns.system_prompt or 'Enable deep thinking subroutine.' -%}\n{%- endif -%}\n\n{# --------------------------- Append tools block ----------------------- #}\n{%- if tools is not none -%}\n {%- if ns.system_prompt -%}\n {%- set ns.system_prompt = ns.system_prompt ~ '\n\nYou have the following functions available:\n\n' -%}\n {%- else -%}\n {%- set ns.system_prompt = 'You have the following functions available:\n\n' -%}\n {%- endif -%}\n {%- for t in tools -%}\n {%- set ns.system_prompt = ns.system_prompt ~ \"```json\n\" ~ (t | tojson(indent=4)) ~ \"\n```\n\n\" -%}\n {%- endfor -%}\n{%- endif -%}\n\n{{- bos_token -}}{{- ns.system_prompt -}}\n\n{# --------------------------- Iterate conversation --------------------- #}\n{%- for m in messages -%}\n {# --------------------------- USER ---------------------------------- #}\n {%- if m.role == 'user' -%}\n {%- set ns.is_last_user = true -%}\n {%- set txt = m.content if m.content is string else m.content | selectattr('type','equalto','text') | map(attribute='text') | join('') -%}\n {{- \"<|User|>\" -}}{{- txt -}}{{- \"<|Assistant|>\" -}}\n {%- endif -%}\n\n {# --------------------------- ASSISTANT with TOOL CALLS -------------- #}\n {%- if m.role == 'assistant' and m.tool_calls is defined and m.tool_calls -%}\n {%- set ns.is_last_user = false -%}\n {%- set lead = m.content is string and m.content|trim or (m.content and m.content | selectattr('type','equalto','text') | map(attribute='text') | join('')) or '' -%}\n {{- lead -}}{{- \"<|tool▁calls▁begin|>\" -}}\n {%- for call in m.tool_calls -%}\n {{- \"<|tool▁call▁begin|>\" -}}{{- call.type -}}{{- \"<|tool▁sep|>\" -}}{{- call.function.name -}}\n {{- \"\n```json\n\" -}}{{- call.function.arguments -}}{{- \"\n```\" -}}{{- \"<|tool▁call▁end|>\" -}}\n {%- if not loop.last -%}{{- \"\n\" -}}{%- endif -%}\n {%- endfor -%}\n {{- \"<|tool▁calls▁end|>\" -}}{{- \"<|end▁of▁sentence|>\" -}}\n {%- endif -%}\n\n {# --------------------------- ASSISTANT plain ------------------------ #}\n {%- if m.role == 'assistant' and (m.tool_calls is not defined or not m.tool_calls) -%}\n {%- set ns.is_last_user = false -%}\n {%- set txt = m.content if m.content is string else m.content | selectattr('type','equalto','text') | map(attribute='text') | join('') -%}\n {{- txt -}}{{- \"<|end▁of▁sentence|>\" -}}\n {%- endif -%}\n\n {# --------------------------- TOOL output ---------------------------- #}\n {%- if m.role == 'tool' -%}\n {%- set ns.is_last_user = false -%}\n {%- set out_txt = m.content if m.content is string else m.content | selectattr('type','equalto','text') | map(attribute='text') | join('') -%}\n {%- if not ns.outputs_open -%}\n {{- \"<|tool▁outputs▁begin|>\" -}}\n {%- set ns.outputs_open = true -%}\n {%- endif -%}\n {{- \"<|tool▁output▁begin|>\" -}}{{- out_txt -}}{{- \"<|tool▁output▁end|>\" -}}\n {%- if loop.nextitem is defined and loop.nextitem.role == 'tool' -%}\n {{- \"\n\" -}}\n {%- endif -%}\n {%- if loop.nextitem is undefined or loop.nextitem.role != 'tool' -%}\n {{- \"<|tool▁outputs▁end|>\" -}}\n {%- set ns.outputs_open = false -%}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n\n{%- if ns.outputs_open -%}\n {{- \"<|tool▁outputs▁end|>\" -}}\n{%- endif -%}\n\n{%- if add_generation_prompt and not ns.is_last_user -%}\n {{- \"<|Assistant|>\" -}}\n{%- endif -%}\n\n{%- if add_generation_prompt and enable_thinking -%}\n {{- '<think>\\n' -}}\n{%- endif -%}"
6564
  }
 
6560
  "tokenizer_class": "LlamaTokenizerFast",
6561
  "unk_token": null,
6562
  "use_default_system_prompt": false,
6563
+ "chat_template": "{# Copyright 2025-present the Unsloth team. All rights reserved. #}\n{# Licensed under the Apache License, Version 2.0 (the \"License\") #}\n{# Edits made by Unsloth to fix the chat template #}\n{# ==================================================================== #}\n{# Deepseek v3 template with enable_thinking and tools support #}\n{# ==================================================================== #}\n{%- if not enable_thinking is defined %}{% set enable_thinking = false %}{% endif -%}\n{%- if not tools is defined %}{% set tools = none %}{% endif -%}\n{%- if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif -%}\n\n{# --------------------------- Collect system prompt -------------------- #}\n{%- set ns = namespace(system_prompt='', is_last_user=false, outputs_open=false, first_output=true, length=0) -%}\n\n{%- if messages and messages[0].role == 'system' -%}\n {%- set raw = messages[0].content -%}\n {%- set ns.system_prompt = raw if raw is string else raw[0].text -%}\n {%- set messages = messages[1:] -%}\n{%- endif -%}\n\n{%- set ns.length = messages|length - 1 -%}\n\n{# --------------------------- Inject deep thinking --------------------- #}\n{%- if enable_thinking -%}\n {%- set ns.system_prompt = ns.system_prompt and 'Enable deep thinking subroutine.\n\n' + ns.system_prompt or 'Enable deep thinking subroutine.' -%}\n{%- endif -%}\n\n{# --------------------------- Append tools block ----------------------- #}\n{%- if tools is not none -%}\n {%- if ns.system_prompt -%}\n {%- set ns.system_prompt = ns.system_prompt + '\n\nYou have the following functions available:\n\n' -%}\n {%- else -%}\n {%- set ns.system_prompt = 'You have the following functions available:\n\n' -%}\n {%- endif -%}\n {%- for t in tools -%}\n {%- set ns.system_prompt = ns.system_prompt + \"```json\n\" + (t | tojson(indent=4)) + \"\n```\n\n\" -%}\n {%- endfor -%}\n{%- endif -%}\n\n{{- bos_token -}}{{- ns.system_prompt -}}\n\n{# --------------------------- Iterate conversation --------------------- #}\n{%- for m in messages -%}\n {# --------------------------- USER ---------------------------------- #}\n {%- if m.role == 'user' -%}\n {%- set ns.is_last_user = true -%}\n {%- set txt = m.content if m.content is string else m.content | selectattr('type','equalto','text') | map(attribute='text') | join('') -%}\n {{- \"<|User|>\" -}}{{- txt -}}\n {%- if loop.index0 != ns.length -%}\n {%- set ns.is_last_user = false -%}\n {{- \"<|Assistant|>\" -}}\n {%- endif -%}\n {%- endif -%}\n\n {# --------------------------- ASSISTANT with TOOL CALLS -------------- #}\n {%- if m.role == 'assistant' and m.tool_calls is defined and m.tool_calls -%}\n {%- set ns.is_last_user = false -%}\n {%- set lead = m.content is string and m.content|trim or (m.content and m.content | selectattr('type','equalto','text') | map(attribute='text') | join('')) or '' -%}\n {{- lead -}}{{- \"<|tool▁calls▁begin|>\" -}}\n {%- for call in m.tool_calls -%}\n {{- \"<|tool▁call▁begin|>\" -}}{{- call.type -}}{{- \"<|tool▁sep|>\" -}}{{- call.function.name -}}\n {{- \"\n```json\n\" -}}{{- call.function.arguments -}}{{- \"\n```\" -}}{{- \"<|tool▁call▁end|>\" -}}\n {%- if not loop.last -%}{{- \"\n\" -}}{%- endif -%}\n {%- endfor -%}\n {{- \"<|tool▁calls▁end|>\" -}}{{- \"<|end▁of▁sentence|>\" -}}\n {%- endif -%}\n\n {# --------------------------- ASSISTANT plain ------------------------ #}\n {%- if m.role == 'assistant' and (m.tool_calls is not defined or not m.tool_calls) -%}\n {%- set ns.is_last_user = false -%}\n {%- set txt = m.content if m.content is string else m.content | selectattr('type','equalto','text') | map(attribute='text') | join('') -%}\n {{- txt -}}{{- \"<|end▁of▁sentence|>\" -}}\n {%- endif -%}\n\n {# --------------------------- TOOL output ---------------------------- #}\n {%- if m.role == 'tool' -%}\n {%- set ns.is_last_user = false -%}\n {%- set out_txt = m.content if m.content is string else m.content | selectattr('type','equalto','text') | map(attribute='text') | join('') -%}\n {%- if not ns.outputs_open -%}\n {{- \"<|tool▁outputs▁begin|>\" -}}\n {%- set ns.outputs_open = true -%}\n {%- endif -%}\n {{- \"<|tool▁output▁begin|>\" -}}{{- out_txt -}}{{- \"<|tool▁output▁end|>\" -}}\n {%- if loop.nextitem is defined and loop.nextitem.role == 'tool' -%}\n {{- \"\n\" -}}\n {%- endif -%}\n {%- if loop.nextitem is not defined or loop.nextitem.role != 'tool' -%}\n {{- \"<|tool▁outputs▁end|>\" -}}\n {%- set ns.outputs_open = false -%}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n\n{%- if ns.outputs_open -%}\n {{- \"<|tool▁outputs▁end|>\" -}}\n{%- endif -%}\n\n{%- if add_generation_prompt and ns.is_last_user -%}\n {{- \"<|Assistant|>\" -}}\n{%- endif -%}\n\n{%- if add_generation_prompt and enable_thinking -%}\n {{- '<think>\\n' -}}\n{%- endif -%}\n{# Copyright 2025-present the Unsloth team. All rights reserved. #}\n{# Licensed under the Apache License, Version 2.0 (the \"License\") #}"
6564
  }