
    oi+                       / S Qr SSKJrJr  SSKJrJr  SSKJr  SSK	J
r
  SSKrSSKrSSK7  SS	KJr  SSKrSS
KJrJr  \r0 r0 rSrSrSr\\S\4\S'   S\S'   SrSrSr\\S\4\S'   S\S'   SrSrSr\\S\4\S'   S\S'   Sr Sr!Sr"\ \"S\!4\S'   S\S'   Sr#Sr$Sr%\#\%S\$4\S'   S\S'   Sr&S r'Sr(\&\(S\'4\S!'   S"\S!'   S#r)S$r*Sr+\)\+S\*4\S%'   S&\S%'   \S%   \S''   \S%   \S''   S(r,S)r-Sr.\,\.S\-4\S*'   S+\S*'   S,r/S-r0S.r1\/\1S\04\S/'   S\S/'   S0\-   r2S1r3S2SS3.S4r4\2\4S\34\S4'   S\S4'   \/r5\0S5-   r6S.r7\5\7S\64\S6'   S\S6'   \2r8\3S5-   r9\4r:\8\:S\94\S7'   S\S7'   S8r;S9r<Sr=\;\=S\<4\S:'   S\S:'   \;\=S\<4\S;'   S\S;'   S<r>S=r?S>r@\>\@S\?4\S?'   S\S?'   \S?   \S@'   S\S@'   \S?   \SA'   S\SA'    SBrASCrBSrC\A\CS\B4\SD'   SE\SD'   \A\CS\B4\SF'   SE\SF'   SG H  rD\SD   \\D'   SE\\D'   M     SHrESIrFSrGSJrH\E\GS\F4\SK'   \H\SK'   \E\GS\F4\SL'   \H\SL'   \E\GS\F4\SM'   \H\SM'   \E\GS\F4\SN'   \H\SN'   SOrISPrJSQ\J SR3rKSrL\I\LS\K4\SS'   S\SS'   STrMSUrNS.rO\M\OS\N4\SV'   S\SV'   \M\OS\N4\SW'   S\SW'   SXrPSYrQSrR\P\RS\Q4\SZ'   S\SZ'   \P\RS\Q4\S['   S\S['   S\rSS]rTS.rU\S\US\T4\S^'   S\S^'   \S\US\T4\S_'   S\S_'   S`rVSarWSbrX\V\XS\W4\Sc'   S\Sc'   \V\XS\W4\Sd'   S\Sd'   SerYSfrQSrR\Y\RS\Q4\Sg'   S\Sg'   ShrZ\Z\RS\Q4\Si'   S\Si'   Sjr[Sr\\[\\SS4\Sk'   S\Sk'   Slr]Smr^Snr_\]\_S\^4\So'   S\So'   Spr`SqraSrrb\`\bS\a4\Ss'   S\Ss'   SSt\cSu\cSv\c4Sw jjrdSSxSySzS{S|.SS4S} jreS~ rfS rgS rh      SS jri/ 4S jrj    SS jrkS rl    SS jrmSS jrnS roSS jrpg))
get_chat_templatetest_chat_templatestest_hf_gguf_equivalenceremove_special_tokensto_sharegptstandardize_sharegptstandardize_data_formatsapply_chat_templatetrain_on_responses_onlytest_construct_chat_template    StoppingCriteriaStoppingCriteriaList)
LongTensorFloatTensor)logger   )patch_saving_functionsN)*)patch_tokenizer)r
   r   aR  {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ messages[0]['content'] + '
' }}{% set loop_messages = messages[1:] %}{% else %}{{ '{system_message}' + '
' }}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ '>>> User: ' + message['content'] + '
' }}{% elif message['role'] == 'assistant' %}{{ '>>> Assistant: ' + message['content'] + eos_token + '
' }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '>>> Assistant: ' }}{% endif %}a4  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}{{ .System }}
{{ end }}{{ if .Prompt }}>>> User: {{ .Prompt }}
{{ end }}>>> Assistant: {{ .Response }}{__EOS_TOKEN__}
"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
SYSTEM """You are a helpful assistant to the user"""
	eos_tokenFunslothz'You are a helpful assistant to the useraw  {% for message in messages %}{% if message['role'] == 'user' %}{{ '<|user|>
' + message['content'] + eos_token + '
' }}{% elif message['role'] == 'assistant' %}{{ '<|assistant|>
' + message['content'] + eos_token + '
' }}{% else %}{{ '<|system|>
' + message['content'] + eos_token + '
' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>
' }}{% endif %}a&  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}<|system|>
{{ .System }}{__EOS_TOKEN__}
{{ end }}{{ if .Prompt }}<|user|>
{{ .Prompt }}{__EOS_TOKEN__}
{{ end }}<|assistant|>
{{ .Response }}{__EOS_TOKEN__}
"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
zephyra  {% for message in messages %}{% if message['role'] == 'user' %}{{'<|im_start|>user
' + message['content'] + '<|im_end|>
'}}{% elif message['role'] == 'assistant' %}{{'<|im_start|>assistant
' + message['content'] + '<|im_end|>
' }}{% else %}{{ '<|im_start|>system
' + message['content'] + '<|im_end|>
' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}aH  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ .Response }}<|im_end|>
"""
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
z
<|im_end|>Tchatmla  {{ bos_token }}{% if messages[0]['role'] == 'system' %}{% if messages[1]['role'] == 'user' %}{{ '[INST] ' + messages[0]['content'] + ' ' + messages[1]['content'] + ' [/INST]' }}{% set loop_messages = messages[2:] %}{% else %}{{ '[INST] ' + messages[0]['content'] + ' [/INST]' }}{% set loop_messages = messages[1:] %}{% endif %}{% else %}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}z
FROM {__FILE_LOCATION__}
TEMPLATE """[INST] {{ if .System }}{{ .System }} {{ end }}{{ .Prompt }} [/INST]"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
mistrala  {% if messages[0]['role'] == 'system' %}{% if messages[1]['role'] == 'user' %}{{ bos_token + '[INST] <<SYS>>
' + messages[0]['content'] + '
<</SYS>>

' + messages[1]['content'] + ' [/INST]' }}{% set loop_messages = messages[2:] %}{% else %}{{ bos_token + '[INST] ' + messages[0]['content'] + ' [/INST]' }}{% set loop_messages = messages[1:] %}{% endif %}{% else %}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + message['content'].strip() + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + message['content'].strip() + ' ' + eos_token }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}z
FROM {__FILE_LOCATION__}
TEMPLATE """[INST] <<SYS>>{{ .System }}<</SYS>>

{{ .Prompt }} [/INST]"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
llamaa?  {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ messages[0]['content'] + ' ' }}{% set loop_messages = messages[1:] %}{% else %}{{ '{system_message}' + ' ' }}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ 'USER: ' + message['content'] + ' ' }}{% elif message['role'] == 'assistant' %}{{ 'ASSISTANT: ' + message['content'] + eos_token }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'ASSISTANT:' }}{% endif %}z
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}{{ .System }} {{ end }}{{ if .Prompt }}USER: {{ .Prompt }} {{ end }}ASSISTANT: {{ .Response }} {__EOS_TOKEN__}"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
vicunazA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.aR  {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ messages[0]['content'] + '
' }}{% set loop_messages = messages[1:] %}{% else %}{{ '{system_message}' + '
' }}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ '### Human: ' + message['content'] + '
' }}{% elif message['role'] == 'assistant' %}{{ '### Assistant: ' + message['content'] + eos_token + '
' }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '### Assistant:' }}{% endif %}a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}{{ .System }}
{{ end }}{{ if .Prompt }}### Human: {{ .Prompt }}
{{ end }}### Assistant: {{ .Response }}{__EOS_TOKEN__}
"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
SYSTEM """A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions."""

vicuna_oldzA chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human\'s questions.z
vicuna olda[  {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ messages[0]['content'] + '

' }}{% set loop_messages = messages[1:] %}{% else %}{{ '{system_message}' + '

' }}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ '### Instruction:
' + message['content'] + '

' }}{% elif message['role'] == 'assistant' %}{{ '### Response:
' + message['content'] + eos_token + '

' }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '### Response:
' }}{% endif %}a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}{{ .System }}

{{ end }}{{ if .Prompt }}### Instruction:
{{ .Prompt }}{{ end }}

### Response:
{{ .Response }}{__EOS_TOKEN__}

"""
PARAMETER stop "{__EOS_TOKEN__}"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
SYSTEM """Below are some instructions that describe some tasks. Write responses that appropriately complete each request."""
alpacaoBelow are some instructions that describe some tasks. Write responses that appropriately complete each request.a~  {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{'<start_of_turn>user
' + messages[0]['content'] | trim + ' ' + messages[1]['content'] | trim + '<end_of_turn>
'}}{% set messages = messages[2:] %}{% endif %}{% for message in messages %}{% if message['role'] == 'user' %}{{'<start_of_turn>user
' + message['content'] | trim + '<end_of_turn>
'}}{% elif message['role'] == 'assistant' %}{{'<start_of_turn>model
' + message['content'] | trim + '<end_of_turn>
' }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<start_of_turn>model
' }}{% endif %}a\  
FROM {__FILE_LOCATION__}
TEMPLATE """<start_of_turn>user
{{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}<end_of_turn>
<start_of_turn>model
{{ .Response }}<end_of_turn>
"""
PARAMETER repeat_penalty 1
PARAMETER stop "<start_of_turn>"
PARAMETER stop "<end_of_turn>"
PARAMETER penalize_newline false
PARAMETER temperature 1.5
PARAMETER min_p 0.1
z<end_of_turn>gemma{{ bos_token }}a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ .Response }}<|im_end|>
"""
PARAMETER repeat_penalty 1
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
PARAMETER penalize_newline false
PARAMETER temperature 1.5
PARAMETER min_p 0.1
z<|im_start|>)z<start_of_turn>z<eos>gemma_chatmlzPARAMETER num_ctx 4096
gemma2gemma2_chatmla'  {{ bos_token }}{% for message in messages %}{% if message['role'] == 'user' %}{{ '<|start_header_id|>user<|end_header_id|>

' + message['content'] | trim + '<|eot_id|>' }}{% elif message['role'] == 'assistant' %}{{ '<|start_header_id|>assistant<|end_header_id|>

' + message['content'] | trim + '<|eot_id|>' }}{% else %}{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>

' + message['content'] | trim + '<|eot_id|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>

' }}{% endif %}a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|>

{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>

{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>

{{ .Response }}<|eot_id|>"""
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
zllama-3llama3as  {% for message in messages %}{% if message['role'] == 'user' %}{{'<|user|>
' + message['content'] + '<|end|>
'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>
' + message['content'] + '<|end|>
'}}{% else %}{{'<|' + message['role'] + '|>
' + message['content'] + '<|end|>
'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>
' }}{% endif %}a?  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}<|system|>
{{ .System }}<|end|>
{{ end }}{{ if .Prompt }}<|user|>
{{ .Prompt }}<|end|>
{{ end }}<|assistant|>
{{ .Response }}<|end|>
"""
PARAMETER stop "<|end|>"
PARAMETER stop "<|user|>"
PARAMETER stop "<|assistant|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
z<|end|>zphi-3zphi-35zphi-3.5a  {{- bos_token }}
{%- if custom_tools is defined %}
    {%- set tools = custom_tools %}
{%- endif %}
{%- if not tools_in_user_message is defined %}
    {%- set tools_in_user_message = true %}
{%- endif %}
{%- if not date_string is defined %}
    {%- set date_string = "26 July 2024" %}
{%- endif %}
{%- if not tools is defined %}
    {%- set tools = none %}
{%- endif %}

{#- This block extracts the system message, so we can slot it into the right place. #}
{%- if messages[0]['role'] == 'system' %}
    {%- set system_message = messages[0]['content'] %}
    {%- set messages = messages[1:] %}
{%- else %}
    {%- set system_message = "{system_message}" %}
{%- endif %}

{#- System message + builtin tools #}
{{- "<|start_header_id|>system<|end_header_id|>

" }}
{%- if builtin_tools is defined or tools is not none %}
    {{- "Environment: ipython
" }}
{%- endif %}
{%- if builtin_tools is defined %}
    {{- "Tools: " + builtin_tools | reject('equalto', 'code_interpreter') | join(", ") + "

"}}
{%- endif %}
{{- "Cutting Knowledge Date: December 2023
" }}
{{- "Today Date: " + date_string + "

" }}
{%- if tools is not none and not tools_in_user_message %}
    {{- "You have access to the following functions. To call a function, please respond with JSON for a function call." }}
    {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
    {{- "Do not use variables.

" }}
    {%- for t in tools %}
        {{- t | tojson(indent=4) }}
        {{- "

" }}
    {%- endfor %}
{%- endif %}
{{- system_message }}
{{- "<|eot_id|>" }}

{#- Custom tools are passed in a user message with some extra guidance #}
{%- if tools_in_user_message and not tools is none %}
    {#- Extract the first user message so we can plug it in here #}
    {%- if messages | length != 0 %}
        {%- set first_user_message = messages[0]['content'] %}
        {%- set messages = messages[1:] %}
    {%- else %}
        {{- raise_exception("Cannot put tools in the first user message when there's no first user message!") }}
{%- endif %}
    {{- '<|start_header_id|>user<|end_header_id|>

' -}}
    {{- "Given the following functions, please respond with a JSON for a function call " }}
    {{- "with its proper arguments that best answers the given prompt.

" }}
    {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
    {{- "Do not use variables.

" }}
    {%- for t in tools %}
        {{- t | tojson(indent=4) }}
        {{- "

" }}
    {%- endfor %}
    {{- first_user_message + "<|eot_id|>"}}
{%- endif %}

{%- for message in messages %}
    {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %}
        {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>

'+ message['content'] + '<|eot_id|>' }}
    {%- elif 'tool_calls' in message %}
        {%- if not message.tool_calls|length == 1 %}
            {{- raise_exception("This model only supports single tool-calls at once!") }}
        {%- endif %}
        {%- set tool_call = message.tool_calls[0].function %}
        {%- if builtin_tools is defined and tool_call.name in builtin_tools %}
            {{- '<|start_header_id|>assistant<|end_header_id|>

' -}}
            {{- "<|python_tag|>" + tool_call.name + ".call(" }}
            {%- for arg_name, arg_val in tool_call.arguments | items %}
                {{- arg_name + '="' + arg_val + '"' }}
                {%- if not loop.last %}
                    {{- ", " }}
                {%- endif %}
                {%- endfor %}
            {{- ")" }}
        {%- else  %}
            {{- '<|start_header_id|>assistant<|end_header_id|>

' -}}
            {{- '{"name": "' + tool_call.name + '", ' }}
            {{- '"parameters": ' }}
            {{- tool_call.arguments | tojson }}
            {{- "}" }}
        {%- endif %}
        {%- if builtin_tools is defined %}
            {#- This means we're in ipython mode #}
            {{- "<|eom_id|>" }}
        {%- else %}
            {{- "<|eot_id|>" }}
        {%- endif %}
    {%- elif message.role == "tool" or message.role == "ipython" %}
        {{- "<|start_header_id|>ipython<|end_header_id|>

" }}
        {%- if message.content is mapping or message.content is iterable %}
            {{- message.content | tojson }}
        {%- else %}
            {{- message.content }}
        {%- endif %}
        {{- "<|eot_id|>" }}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|start_header_id|>assistant<|end_header_id|>

' }}
{%- endif %}
au  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .Messages }}
{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>
{{- if .System }}

{{ .System }}
{{- end }}
{{- if .Tools }}

You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the original use question.
{{- end }}
{{- end }}<|eot_id|>
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
{{- if and $.Tools $last }}

Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.

Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.

{{ $.Tools }}
{{- end }}

{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>

{{ end }}
{{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|>
{{- if .ToolCalls }}

{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}{{ end }}
{{- else }}

{{ .Content }}{{ if not $last }}<|eot_id|>{{ end }}
{{- end }}
{{- else if eq .Role "tool" }}<|start_header_id|>ipython<|end_header_id|>

{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>

{{ end }}
{{- end }}
{{- end }}
{{- else }}
{{- if .System }}<|start_header_id|>system<|end_header_id|>

{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>

{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>

{{ end }}{{ .Response }}{{ if .Response }}<|eot_id|>{{ end }}"""
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
PARAMETER stop "<|eom_id|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
z	llama-3.1 zllama-31)z	llama-3.2z	llama-3.3zllama-32zllama-33a	  {%- if tools %}
    {{- '<|im_start|>system\n' }}
    {%- if messages[0]['role'] == 'system' %}
        {{- messages[0]['content'] }}
    {%- else %}
        {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
    {%- endif %}
    {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
    {%- for tool in tools %}
        {{- "\n" }}
        {{- tool | tojson }}
    {%- endfor %}
    {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
    {%- if messages[0]['role'] == 'system' %}
        {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
    {%- else %}
        {{- '<|im_start|>system\n{system_message}<|im_end|>\n' }}
    {%- endif %}
{%- endif %}
{%- for message in messages %}
    {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
        {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
    {%- elif message.role == "assistant" %}
        {{- '<|im_start|>' + message.role }}
        {%- if message.content %}
            {{- '\n' + message.content }}
        {%- endif %}
        {%- for tool_call in message.tool_calls %}
            {%- if tool_call.function is defined %}
                {%- set tool_call = tool_call.function %}
            {%- endif %}
            {{- '\n<tool_call>\n{"name": "' }}
            {{- tool_call.name }}
            {{- '", "arguments": ' }}
            {{- tool_call.arguments | tojson }}
            {{- '}\n</tool_call>' }}
        {%- endfor %}
        {{- '<|im_end|>\n' }}
    {%- elif message.role == "tool" %}
        {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}            {{- '<|im_start|>user' }}
        {%- endif %}
        {{- '\n<tool_response>\n' }}
        {{- message.content }}
        {{- '\n</tool_response>' }}
        {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
            {{- '<|im_end|>\n' }}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant\n' }}
{%- endif %}
a]  
FROM {__FILE_LOCATION__}
TEMPLATE """{{- if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}

# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
{{- else }}
{{- if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "<|endoftext|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
zDYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.zqwen-2.5zqwen-25qwen25zqwen2.5a  {% for message in messages %}{% if (message['role'] == 'system') %}{{'<|im_start|>system<|im_sep|>' + message['content'] + '<|im_end|>'}}{% elif (message['role'] == 'user') %}{{'<|im_start|>user<|im_sep|>' + message['content'] + '<|im_end|>'}}{% elif (message['role'] == 'assistant') %}{{'<|im_start|>assistant<|im_sep|>' + message['content'] + '<|im_end|>'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant<|im_sep|>' }}{% endif %}z{{ if .System }}<|im_start|><|system|><|im_sep|>{{ .System }}<|im_end|>{{ end }}{{ if .Prompt }}<|im_start|><|user|><|im_sep|>{{ .Prompt }}<|im_end|>{{ end }}<|im_start|><|assistant|><|im_sep|>{{ .Response }}<|im_end|>z&
FROM {__FILE_LOCATION__}
TEMPLATE """z"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_sep|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
zphi-4a  {{ bos_token }}
{%- if messages[0]['role'] == 'system' -%}
    {%- if messages[0]['content'] is string -%}
        {%- set first_user_prefix = messages[0]['content'] + '

' -%}
    {%- else -%}
        {%- set first_user_prefix = messages[0]['content'][0]['text'] + '

' -%}
    {%- endif -%}
    {%- set loop_messages = messages[1:] -%}
{%- else -%}
    {%- set first_user_prefix = "" -%}
    {%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_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 -%}
    {{ '<start_of_turn>' + role + '
' + (first_user_prefix if loop.first else "") }}
    {%- if message['content'] is string -%}
        {{ message['content'] | trim }}
    {%- elif message['content'] is iterable -%}
        {%- for item in message['content'] -%}
            {%- if item['type'] == 'image' -%}
                {{ '<start_of_image>' }}
            {%- elif item['type'] == 'text' -%}
                {{ item['text'] | trim }}
            {%- endif -%}
        {%- endfor -%}
    {%- else -%}
        {{ raise_exception("Invalid content type") }}
    {%- endif -%}
    {{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
    {{ '<start_of_turn>model
' }}
{%- endif -%}
a8  
FROM {__FILE_LOCATION__}
TEMPLATE """{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if or (eq .Role "user") (eq .Role "system") }}<start_of_turn>user
{{ .Content }}<end_of_turn>
{{ if $last }}<start_of_turn>model
{{ end }}
{{- else if eq .Role "assistant" }}<start_of_turn>model
{{ .Content }}{{ if not $last }}<end_of_turn>
{{ end }}
{{- end }}
{{- end }}"""
PARAMETER stop "<end_of_turn>"
PARAMETER stop "<eos>"
PARAMETER temperature 0.1
PARAMETER min_p 0.0
PARAMETER top_k 64
PARAMETER top_p 0.95
PARAMETER num_predict 32768
zgemma-3gemma3an  
{%- if tools %}
    {{- '<|im_start|>system
' }}
    {%- if messages[0].role == 'system' %}
        {{- messages[0].content + '

' }}
    {%- endif %}
    {{- "# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>" }}
    {%- for tool in tools %}
        {{- "
" }}
        {{- tool | tojson }}
    {%- endfor %}
    {{- "
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{\"name\": <function-name>, \"arguments\": <args-json-object>}
</tool_call><|im_end|>
" }}
{%- else %}
    {%- if messages[0].role == 'system' %}
        {{- '<|im_start|>system
' + messages[0].content + '<|im_end|>
' }}
    {%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for forward_message in messages %}
    {%- set index = (messages|length - 1) - loop.index0 %}
    {%- set message = messages[index] %}
    {%- set current_content = message.content if message.content is not none else '' %}
    {%- set tool_start = '<tool_response>' %}
    {%- set tool_start_length = tool_start|length %}
    {%- set start_of_message = current_content[:tool_start_length] %}
    {%- set tool_end = '</tool_response>' %}
    {%- set tool_end_length = tool_end|length %}
    {%- set start_pos = (current_content|length) - tool_end_length %}
    {%- if start_pos < 0 %}
        {%- set start_pos = 0 %}
    {%- endif %}
    {%- set end_of_message = current_content[start_pos:] %}
    {%- if ns.multi_step_tool and message.role == "user" and not(start_of_message == tool_start and end_of_message == tool_end) %}
        {%- set ns.multi_step_tool = false %}
        {%- set ns.last_query_index = index %}
    {%- endif %}
{%- endfor %}
{%- for message in messages %}
    {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
        {{- '<|im_start|>' + message.role + '
' + message.content + '<|im_end|>' + '
' }}
    {%- elif message.role == "assistant" %}
        {%- set content = message.content %}
        {%- set reasoning_content = '' %}
        {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
            {%- set reasoning_content = message.reasoning_content %}
        {%- else %}
            {%- if '</think>' in message.content %}
                {%- set content = (message.content.split('</think>')|last).lstrip('
') %}
                {%- set reasoning_content = (message.content.split('</think>')|first).rstrip('
') %}
                {%- set reasoning_content = (reasoning_content.split('<think>')|last).lstrip('
') %}
            {%- endif %}
        {%- endif %}
        {%- if loop.index0 > ns.last_query_index %}
            {%- if loop.last or (not loop.last and reasoning_content) %}
                {{- '<|im_start|>' + message.role + '
<think>
' + reasoning_content.strip('
') + '
</think>

' + content.lstrip('
') }}
            {%- else %}
                {{- '<|im_start|>' + message.role + '
' + content }}
            {%- endif %}
        {%- else %}
            {{- '<|im_start|>' + message.role + '
' + content }}
        {%- endif %}
        {%- if message.tool_calls %}
            {%- for tool_call in message.tool_calls %}
                {%- if (loop.first and content) or (not loop.first) %}
                    {{- '
' }}
                {%- endif %}
                {%- if tool_call.function %}
                    {%- set tool_call = tool_call.function %}
                {%- endif %}
                {{- '<tool_call>
{"name": "' }}
                {{- tool_call.name }}
                {{- '", "arguments": ' }}
                {%- if tool_call.arguments is string %}
                    {{- tool_call.arguments }}
                {%- else %}
                    {{- tool_call.arguments | tojson }}
                {%- endif %}
                {{- '}
</tool_call>' }}
            {%- endfor %}
        {%- endif %}
        {{- '<|im_end|>
' }}
    {%- elif message.role == "tool" %}
        {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
            {{- '<|im_start|>user' }}
        {%- endif %}
        {{- '
<tool_response>
' }}
        {{- message.content }}
        {{- '
</tool_response>' }}
        {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
            {{- '<|im_end|>
' }}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant
' }}
    {%- if enable_thinking is defined and enable_thinking is false %}
        {{- '<think>

</think>

' }}
    {%- endif %}
{%- endif %}
a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{- if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}

# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
{{- else }}
{{- if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "<|im_start|>"
PARAMETER temperature 0.6
PARAMETER min_p 0.0
PARAMETER top_k 20
PARAMETER top_p 0.95
PARAMETER repeat_penalty 1
zqwen-3qwen3aZ  {{ bos_token }}
{%- if messages[0]['role'] == 'system' -%}
    {%- if messages[0]['content'] is string -%}
        {%- set first_user_prefix = messages[0]['content'] + '

' -%}
    {%- else -%}
        {%- set first_user_prefix = messages[0]['content'][0]['text'] + '

' -%}
    {%- endif -%}
    {%- set loop_messages = messages[1:] -%}
{%- else -%}
    {%- set first_user_prefix = "" -%}
    {%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_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 -%}
    {{ '<start_of_turn>' + role + '
' + (first_user_prefix if loop.first else "") }}
    {%- if message['content'] is string -%}
        {{ message['content'] | trim }}
    {%- elif message['content'] is iterable -%}
        {%- for item in message['content'] -%}
            {%- if item['type'] == 'audio' -%}
                {{ '<audio_soft_token>' }}
            {%- elif item['type'] == 'image' -%}
                {{ '<image_soft_token>' }}
            {%- elif item['type'] == 'text' -%}
                {{ item['text'] | trim }}
            {%- endif -%}
        {%- endfor -%}
    {%- else -%}
        {{ raise_exception("Invalid content type") }}
    {%- endif -%}
    {{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
    {{'<start_of_turn>model
'}}
{%- endif -%}
a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if or (eq .Role "user") (eq .Role "system") }}<start_of_turn>user
{{ .Content }}<end_of_turn>
{{ if $last }}<start_of_turn>model
{{ end }}
{{- else if eq .Role "assistant" }}<start_of_turn>model
{{ .Content }}{{ if not $last }}<end_of_turn>
{{ end }}
{{- end }}
{{- end }}"""
zgemma-3ngemma3nuD  {#-
  In addition to the normal inputs of `messages` and `tools`, this template also accepts the
  following kwargs:
  - "builtin_tools": A list, can contain "browser" and/or "python".
  - "model_identity": A string that optionally describes the model identity.
  - "reasoning_effort": A string that describes the reasoning effort, defaults to "medium".
 #}

{#- Tool Definition Rendering ============================================== #}
{%- macro render_typescript_type(param_spec, required_params, is_nullable=false) -%}
    {%- if param_spec.type == "array" -%}
        {%- if param_spec['items'] -%}
            {%- if param_spec['items']['type'] == "string" -%}
                {{- "string[]" }}
            {%- elif param_spec['items']['type'] == "number" -%}
                {{- "number[]" }}
            {%- elif param_spec['items']['type'] == "integer" -%}
                {{- "number[]" }}
            {%- elif param_spec['items']['type'] == "boolean" -%}
                {{- "boolean[]" }}
            {%- else -%}
                {%- set inner_type = render_typescript_type(param_spec['items'], required_params) -%}
                {%- if inner_type == "object | object" or inner_type|length > 50 -%}
                    {{- "any[]" }}
                {%- else -%}
                    {{- inner_type + "[]" }}
                {%- endif -%}
            {%- endif -%}
            {%- if param_spec.nullable -%}
                {{- " | null" }}
            {%- endif -%}
        {%- else -%}
            {{- "any[]" }}
            {%- if param_spec.nullable -%}
                {{- " | null" }}
            {%- endif -%}
        {%- endif -%}
    {%- elif param_spec.type is defined and param_spec.type is iterable and param_spec.type is not string and param_spec.type is not mapping and param_spec.type[0] is defined -%}
        {#- Handle array of types like ["object", "object"] from Union[dict, list] #}
        {%- if param_spec.type | length > 1 -%}
            {{- param_spec.type | join(" | ") }}
        {%- else -%}
            {{- param_spec.type[0] }}
        {%- endif -%}
    {%- elif param_spec.oneOf -%}
        {#- Handle oneOf schemas - check for complex unions and fallback to any #}
        {%- set has_object_variants = false -%}
        {%- for variant in param_spec.oneOf -%}
            {%- if variant.type == "object" -%}
                {%- set has_object_variants = true -%}
            {%- endif -%}
        {%- endfor -%}
        {%- if has_object_variants and param_spec.oneOf|length > 1 -%}
            {{- "any" }}
        {%- else -%}
            {%- for variant in param_spec.oneOf -%}
                {{- render_typescript_type(variant, required_params) -}}
                {%- if variant.description %}
                    {{- "// " + variant.description }}
                {%- endif -%}
                {%- if variant.default is defined %}
                    {{ "// default: " + variant.default|tojson }}
                {%- endif -%}
                {%- if not loop.last %}
                    {{- " | " }}
                {% endif -%}
            {%- endfor -%}
        {%- endif -%}
    {%- elif param_spec.type == "string" -%}
        {%- if param_spec.enum -%}
            {{- '"' + param_spec.enum|join('" | "') + '"' -}}
        {%- else -%}
            {{- "string" }}
            {%- if param_spec.nullable %}
                {{- " | null" }}
            {%- endif -%}
        {%- endif -%}
    {%- elif param_spec.type == "number" -%}
        {{- "number" }}
    {%- elif param_spec.type == "integer" -%}
        {{- "number" }}
    {%- elif param_spec.type == "boolean" -%}
        {{- "boolean" }}

    {%- elif param_spec.type == "object" -%}
        {%- if param_spec.properties -%}
            {{- "{
" }}
            {%- for prop_name, prop_spec in param_spec.properties.items() -%}
                {{- prop_name -}}
                {%- if prop_name not in (param_spec.required or []) -%}
                    {{- "?" }}
                {%- endif -%}
                {{- ": " }}
                {{ render_typescript_type(prop_spec, param_spec.required or []) }}
                {%- if not loop.last -%}
                    {{-", " }}
                {%- endif -%}
            {%- endfor -%}
            {{- "}" }}
        {%- else -%}
            {{- "object" }}
        {%- endif -%}
    {%- else -%}
        {{- "any" }}
    {%- endif -%}
{%- endmacro -%}

{%- macro render_tool_namespace(namespace_name, tools) -%}
    {{- "## " + namespace_name + "

" }}
    {{- "namespace " + namespace_name + " {

" }}
    {%- for tool in tools %}
        {%- set tool = tool.function %}
        {{- "// " + tool.description + "
" }}
        {{- "type "+ tool.name + " = " }}
        {%- if tool.parameters and tool.parameters.properties %}
            {{- "(_: {
" }}
            {%- for param_name, param_spec in tool.parameters.properties.items() %}
                {%- if param_spec.description %}
                    {{- "// " + param_spec.description + "
" }}
                {%- endif %}
                {{- param_name }}
                {%- if param_name not in (tool.parameters.required or []) -%}
                    {{- "?" }}
                {%- endif -%}
                {{- ": " }}
                {{- render_typescript_type(param_spec, tool.parameters.required or []) }}
                {%- if param_spec.default is defined -%}
                    {%- if param_spec.enum %}
                        {{- ", // default: " + param_spec.default }}
                    {%- elif param_spec.oneOf %}
                        {{- "// default: " + param_spec.default }}
                    {%- else %}
                        {{- ", // default: " + param_spec.default|tojson }}
                    {%- endif -%}
                {%- endif -%}
                {%- if not loop.last %}
                    {{- ",
" }}
                {%- else %}
                    {{- ",
" }}
                {%- endif -%}
            {%- endfor %}
            {{- "}) => any;

" }}
        {%- else -%}
            {{- "() => any;

" }}
        {%- endif -%}
    {%- endfor %}
    {{- "} // namespace " + namespace_name }}
{%- endmacro -%}

{%- macro render_builtin_tools(browser_tool, python_tool) -%}
    {%- if browser_tool %}
        {{- "## browser

" }}
        {{- "// Tool for browsing.
" }}
        {{- "// The `cursor` appears in brackets before each browsing display: `[{cursor}]`.
" }}
        {{- "// Cite information from the tool using the following format:
" }}
        {{- "// `【{cursor}†L{line_start}(-L{line_end})?】`, for example: `【6†L9-L11】` or `【8†L3】`.
" }}
        {{- "// Do not quote more than 10 words directly from the tool output.
" }}
        {{- "// sources=web (default: web)
" }}
        {{- "namespace browser {

" }}
        {{- "// Searches for information related to `query` and displays `topn` results.
" }}
        {{- "type search = (_: {
" }}
        {{- "query: string,
" }}
        {{- "topn?: number, // default: 10
" }}
        {{- "source?: string,
" }}
        {{- "}) => any;

" }}
        {{- "// Opens the link `id` from the page indicated by `cursor` starting at line number `loc`, showing `num_lines` lines.
" }}
        {{- "// Valid link ids are displayed with the formatting: `【{id}†.*】`.
" }}
        {{- "// If `cursor` is not provided, the most recent page is implied.
" }}
        {{- "// If `id` is a string, it is treated as a fully qualified URL associated with `source`.
" }}
        {{- "// If `loc` is not provided, the viewport will be positioned at the beginning of the document or centered on the most relevant passage, if available.
" }}
        {{- "// Use this function without `id` to scroll to a new location of an opened page.
" }}
        {{- "type open = (_: {
" }}
        {{- "id?: number | string, // default: -1
" }}
        {{- "cursor?: number, // default: -1
" }}
        {{- "loc?: number, // default: -1
" }}
        {{- "num_lines?: number, // default: -1
" }}
        {{- "view_source?: boolean, // default: false
" }}
        {{- "source?: string,
" }}
        {{- "}) => any;

" }}
        {{- "// Finds exact matches of `pattern` in the current page, or the page given by `cursor`.
" }}
        {{- "type find = (_: {
" }}
        {{- "pattern: string,
" }}
        {{- "cursor?: number, // default: -1
" }}
        {{- "}) => any;

" }}
        {{- "} // namespace browser

" }}
    {%- endif -%}

    {%- if python_tool %}
        {{- "## python

" }}
        {{- "Use this tool to execute Python code in your chain of thought. The code will not be shown to the user. This tool should be used for internal reasoning, but not for code that is intended to be visible to the user (e.g. when creating plots, tables, or files).

" }}
        {{- "When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 120.0 seconds. The drive at '/mnt/data' can be used to save and persist user files. Internet access for this session is UNKNOWN. Depends on the cluster.

" }}
    {%- endif -%}
{%- endmacro -%}

{#- System Message Construction ============================================ #}
{%- macro build_system_message() -%}
    {%- if model_identity is not defined %}
        {%- set model_identity = "You are ChatGPT, a large language model trained by OpenAI." %}
    {%- endif %}
    {{- model_identity + "
" }}
    {{- "Knowledge cutoff: 2024-06
" }}
    {{- "Current date: " + strftime_now("%Y-%m-%d") + "

" }}
    {%- if reasoning_effort is not defined %}
        {%- set reasoning_effort = "medium" %}
    {%- endif %}
    {{- "Reasoning: " + reasoning_effort + "

" }}
    {%- if builtin_tools is defined and builtin_tools is not none %}
        {{- "# Tools

" }}
        {%- set available_builtin_tools = namespace(browser=false, python=false) %}
        {%- for tool in builtin_tools %}
            {%- if tool == "browser" %}
                {%- set available_builtin_tools.browser = true %}
            {%- elif tool == "python" %}
                {%- set available_builtin_tools.python = true %}
            {%- endif %}
        {%- endfor %}
        {{- render_builtin_tools(available_builtin_tools.browser, available_builtin_tools.python) }}
    {%- endif -%}
    {{- "# Valid channels: analysis, commentary, final. Channel must be included for every message." }}
    {%- if tools -%}
        {{- "
Calls to these tools must go to the commentary channel: 'functions'." }}
    {%- endif -%}
{%- endmacro -%}

{#- Main Template Logic ================================================= #}
{#- Set defaults #}

{#- Render system message #}
{{- "<|start|>system<|message|>" }}
{{- build_system_message() }}
{{- "<|end|>" }}

{#- Extract developer message #}
{%- if developer_instructions is defined and developer_instructions is not none %}
    {%- set developer_message = developer_instructions %}
    {%- set loop_messages = messages %}
{%- elif messages[0].role == "developer" or messages[0].role == "system" %}
    {%- set developer_message = messages[0].content %}
    {%- set loop_messages = messages[1:] %}
{%- else %}
    {%- set developer_message = "" %}
    {%- set loop_messages = messages %}
{%- endif %}

{#- Render developer message #}
{%- if developer_message or tools %}
    {{- "<|start|>developer<|message|>" }}
    {%- if developer_message %}
        {{- "# Instructions

" }}
        {{- developer_message }}
    {%- endif %}
    {%- if tools -%}
        {%- if developer_message %}
            {{- "

" }}
        {%- endif %}
        {{- "# Tools

" }}
        {{- render_tool_namespace("functions", tools) }}
    {%- endif -%}
    {{- "<|end|>" }}
{%- endif %}

{#- Render messages #}
{%- set last_tool_call = namespace(name=none) %}
{%- for message in loop_messages -%}
    {#- At this point only assistant/user/tool messages should remain #}
    {%- if message.role == 'assistant' -%}
        {#- Checks to ensure the messages are being passed in the format we expect #}
        {%- if "content" in message %}
            {%- if "<|channel|>analysis<|message|>" in message.content or "<|channel|>final<|message|>" in message.content %}
                {{- raise_exception("You have passed a message containing <|channel|> tags in the content field. Instead of doing this, you should pass analysis messages (the string between '<|message|>' and '<|end|>') in the 'thinking' field, and final messages (the string between '<|message|>' and '<|end|>') in the 'content' field.") }}
            {%- endif %}
        {%- endif %}
        {%- if "thinking" in message %}
            {%- if "<|channel|>analysis<|message|>" in message.thinking or "<|channel|>final<|message|>" in message.thinking %}
                {{- raise_exception("You have passed a message containing <|channel|> tags in the thinking field. Instead of doing this, you should pass analysis messages (the string between '<|message|>' and '<|end|>') in the 'thinking' field, and final messages (the string between '<|message|>' and '<|end|>') in the 'content' field.") }}
            {%- endif %}
        {%- endif %}
        {%- if "tool_calls" in message %}
            {#- We need very careful handling here - we want to drop the tool call analysis message if the model #}
            {#- has output a later <|final|> message, but otherwise we want to retain it. This is the only case #}
            {#- when we render CoT/analysis messages in inference. #}
            {%- set future_final_message = namespace(found=false) %}
            {%- for future_message in loop_messages[loop.index:] %}
                {%- if future_message.role == 'assistant' and "tool_calls" not in future_message %}
                    {%- set future_final_message.found = true %}
                {%- endif %}
            {%- endfor %}
            {#- We assume max 1 tool call per message, and so we infer the tool call name #}
            {#- in "tool" messages from the most recent assistant tool call name #}
            {%- set tool_call = message.tool_calls[0] %}
            {%- if tool_call.function %}
                {%- set tool_call = tool_call.function %}
            {%- endif %}
            {%- if message.content and message.thinking %}
                {{- raise_exception("Cannot pass both content and thinking in an assistant message with tool calls! Put the analysis message in one or the other, but not both.") }}
            {%- elif message.content and not future_final_message.found %}
                {{- "<|start|>assistant<|channel|>analysis<|message|>" + message.content + "<|end|>" }}
            {%- elif message.thinking and not future_final_message.found %}
                {{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
            {%- endif %}
            {{- "<|start|>assistant to=" }}
            {{- "functions." + tool_call.name + "<|channel|>commentary " }}
            {{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
            {%- if tool_call.arguments is string %}
                {{- tool_call.arguments }}
            {%- else %}
                {{- tool_call.arguments|tojson }}
            {%- endif %}
            {{- "<|call|>" }}
            {%- set last_tool_call.name = tool_call.name %}
        {%- elif loop.last and not add_generation_prompt %}
            {#- Only render the CoT if the final turn is an assistant turn and add_generation_prompt is false #}
            {#- This is a situation that should only occur in training, never in inference. #}
            {%- if "thinking" in message %}
                {{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
            {%- endif %}
            {#- <|return|> indicates the end of generation, but <|end|> does not #}
            {#- <|return|> should never be an input to the model, but we include it as the final token #}
            {#- when training, so the model learns to emit it. #}
            {{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
        {%- elif "thinking" in message %}
            {#- CoT is dropped during all previous turns, so we never render it for inference #}
            {{- "<|start|>assistant<|channel|>analysis<|message|>" + message.content + "<|end|>" }}
            {%- set last_tool_call.name = none %}
        {%- else %}
            {#- CoT is dropped during all previous turns, so we never render it for inference #}
            {{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
            {%- set last_tool_call.name = none %}
        {%- endif %}
    {%- elif message.role == 'tool' -%}
        {%- if last_tool_call.name is none %}
            {{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
        {%- endif %}
        {{- "<|start|>functions." + last_tool_call.name }}
        {%- if message.content is string %}
            {{- " to=assistant<|channel|>commentary<|message|>" + message.content + "<|end|>" }}
        {%- else %}
            {{- " to=assistant<|channel|>commentary<|message|>" + message.content|tojson + "<|end|>" }}
        {%- endif %}
    {%- elif message.role == 'user' -%}
        {{- "<|start|>user<|message|>" + message.content + "<|end|>" }}
    {%- endif -%}
{%- endfor -%}

{#- Generation prompt #}
{%- if add_generation_prompt -%}
<|start|>assistant
{%- endif -%}u%  
FROM {__FILE_LOCATION__}
TEMPLATE """<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: {{ currentDate }}
{{- if and .IsThinkSet .Think (ne .ThinkLevel "") }}

Reasoning: {{ .ThinkLevel }}
{{- else if or (not .IsThinkSet) (and .IsThinkSet .Think) }}

Reasoning: medium
{{- end }}

{{- $hasNonBuiltinTools := false }}
{{- if .Tools -}}
{{- $hasBrowserSearch := false }}
{{- $hasBrowserOpen := false }}
{{- $hasBrowserFind := false }}
{{- $hasPython := false }}
  {{- range .Tools }}
    {{- if eq .Function.Name "browser.search" -}}{{- $hasBrowserSearch = true -}}
    {{- else if eq .Function.Name "browser.open" -}}{{- $hasBrowserOpen = true -}}
    {{- else if eq .Function.Name "browser.find" -}}{{- $hasBrowserFind = true -}}
    {{- else if eq .Function.Name "python" -}}{{- $hasPython = true -}}
    {{- else }}{{ $hasNonBuiltinTools = true -}}
    {{- end }}
  {{- end }}
{{- if or $hasBrowserSearch $hasBrowserOpen $hasBrowserFind $hasPython }}

# Tools
{{- if or $hasBrowserSearch $hasBrowserOpen $hasBrowserFind }}

## browser

// Tool for browsing.
// The `cursor` appears in brackets before each browsing display: `[{cursor}]`.
// Cite information from the tool using the following format:
// `【{cursor}†L{line_start}(-L{line_end})?】`, for example: `【6†L9-L11】` or `【8†L3】`.
// Do not quote more than 10 words directly from the tool output.
// sources=web (default: web)
namespace browser {
{{- if $hasBrowserSearch }}

// Searches for information related to `query` and displays `topn` results.
type search = (_: {
query: string,
topn?: number, // default: 10
source?: string,
}) => any;
{{- end }}
{{- if $hasBrowserOpen }}

// Opens the link `id` from the page indicated by `cursor` starting at line number `loc`, showing `num_lines` lines.
// Valid link ids are displayed with the formatting: `【{id}†.*】`.
// If `cursor` is not provided, the most recent page is implied.
// If `id` is a string, it is treated as a fully qualified URL associated with `source`.
// If `loc` is not provided, the viewport will be positioned at the beginning of the document or centered on the most relevant passage, if available.
// Use this function without `id` to scroll to a new location of an opened page.
type open = (_: {
id?: number | string, // default: -1
cursor?: number, // default: -1
loc?: number, // default: -1
num_lines?: number, // default: -1
view_source?: boolean, // default: false
source?: string,
}) => any;
{{- end }}
{{- if $hasBrowserFind }}

// Finds exact matches of `pattern` in the current page, or the page given by `cursor`.
type find = (_: {
pattern: string,
cursor?: number, // default: -1
}) => any;
{{- end }}

} // namespace browser
{{- end }}{{/* end if has browser tools */}}
{{- if $hasPython }}

## python

Use this tool to execute Python code in your chain of thought. The code will not be shown to the user. This tool should be used for internal reasoning, but not for code that is intended to be visible to the user (e.g. when creating plots, tables, or files).

When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 120.0 seconds. The drive at '/mnt/data' can be used to save and persist user files. Internet access for this session is UNKNOWN. Depends on the cluster.
{{- end }}{{/* end if hasPython */}}
{{- end }}{{/* end if has any built-in tools */}}
{{- end }}{{/* end if .Tools */}}

# Valid channels: analysis, commentary, final. Channel must be included for every message.{{ if $hasNonBuiltinTools }}
Calls to these tools must go to the commentary channel: 'functions'.
{{- end -}}<|end|>{{/* end of system */ -}}
{{- if or $hasNonBuiltinTools .System -}}
<|start|>developer<|message|>{{- if $hasNonBuiltinTools }}# Tools

## functions

namespace functions {
{{- range .Tools }}
{{- if not (or (eq .Function.Name "browser.search") (eq .Function.Name "browser.open") (eq .Function.Name "browser.find") (eq .Function.Name "python")) }}
{{if .Function.Description }}
// {{ .Function.Description }}
{{- end }}
{{- if and .Function.Parameters.Properties (gt (len .Function.Parameters.Properties) 0) }}
type {{ .Function.Name }} = (_: {
{{- range $name, $prop := .Function.Parameters.Properties }}
{{- if $prop.Description }}
  // {{ $prop.Description }}
{{- end }}
  {{ $name }}: {{ if gt (len $prop.Type) 1 }}{{ range $i, $t := $prop.Type }}{{ if $i }} | {{ end }}{{ $t }}{{ end }}{{ else }}{{ index $prop.Type 0 }}{{ end }},
{{- end }}
}) => any;
{{- else }}
type {{ .Function.Name }} = () => any;
{{- end }}
{{- end }}{{/* end if not browser tool */}}
{{- end }}{{/* end of range .Tools */}}

} // namespace functions
{{- end }}{{/* end if hasNonBuiltinTools */}}
{{- if .System}}

# Instructions

{{ .System }}
{{- end -}}
<|end|>
{{- end -}}
{{- /* Find the index of the last user message */ -}}
{{- $lastUserIdx := -1 }}
{{- $prefillingContent := false }}
{{- $prefillingThinkingOnly := false }}
{{- range $i, $msg := .Messages }}
  {{- $last := eq (len (slice $.Messages $i)) 1 -}}
  {{- if eq $msg.Role "user" }}
    {{- $lastUserIdx = $i }}
  {{- end -}}
  {{- if and $last (eq $msg.Role "assistant") (gt (len $msg.Content) 0) }}
    {{- $prefillingContent = true }}
  {{- else if and $last (eq $msg.Role "assistant") (gt (len $msg.Thinking) 0) }}
    {{- $prefillingThinkingOnly = true }}
  {{- end }}
{{- end -}}
{{- /* Now render messages */ -}}
{{- range $i, $msg := .Messages }}
  {{- $last := eq (len (slice $.Messages $i)) 1 -}}
  {{- if (ne $msg.Role "system") -}}
    {{- if eq $msg.Role "tool" -}}
      {{- if or (eq $msg.ToolName "python") (eq $msg.ToolName "browser.search") (eq $msg.ToolName "browser.open") (eq $msg.ToolName "browser.find") -}}
        <|start|>{{ $msg.ToolName }} to=assistant<|message|>{{ $msg.Content }}<|end|>
      {{- else -}}
        <|start|>functions.{{ $msg.ToolName }} to=assistant<|message|>{{ $msg.Content }}<|end|>
      {{- end -}}
    {{- else if eq $msg.Role "assistant" -}}
      {{- if and $msg.Thinking (gt $i $lastUserIdx) -}}{{- /* Show thinking only after last user message */ -}}
      <|start|>assistant<|channel|>analysis<|message|>{{ $msg.Thinking }}{{- if not $prefillingThinkingOnly -}}<|end|>{{- end -}}
      {{- end -}}
      {{- if gt (len $msg.Content) 0 -}}
        <|start|>assistant<|channel|>final<|message|>{{ $msg.Content }}{{- if not $prefillingContent -}}<|end|>{{- end -}}
      {{- end -}}
      {{- if gt (len $msg.ToolCalls) 0 -}}
        {{- range $j, $toolCall := $msg.ToolCalls -}}
          {{- $isBuiltin := or (eq $toolCall.Function.Name "python") (eq $toolCall.Function.Name "browser.search") (eq $toolCall.Function.Name "browser.open") (eq $toolCall.Function.Name "browser.find") -}}
          <|start|>assistant<|channel|>{{ if $isBuiltin }}analysis{{ else }}commentary{{ end }} to={{ if not $isBuiltin}}functions.{{end}}{{ $toolCall.Function.Name }} <|constrain|>json<|message|>{{ $toolCall.Function.Arguments }}<|call|>
        {{- end -}}
      {{- end -}}
    {{- else if eq $msg.Role "user" -}}
      <|start|>{{ $msg.Role }}<|message|>{{ $msg.Content }}<|end|>
    {{- end }}
  {{- else }}
  {{- end }}
{{- end -}}
{{- if not (or $prefillingContent $prefillingThinkingOnly) -}}
<|start|>assistant
{{- end -}}"""
PARAMETER temperature 1.0
PARAMETER top_k 0
PARAMETER top_p 1.0
z
<|return|>zgpt-ossgptossa  {%- if tools %}
    {{- '<|im_start|>system\n' }}
    {%- if messages[0].role == 'system' %}
        {{- messages[0].content + '\n\n' }}
    {%- endif %}
    {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
    {%- for tool in tools %}
        {{- "\n" }}
        {{- tool | tojson }}
    {%- endfor %}
    {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
    {%- if messages[0].role == 'system' %}
        {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
    {%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
    {%- set index = (messages|length - 1) - loop.index0 %}
    {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
        {%- set ns.multi_step_tool = false %}
        {%- set ns.last_query_index = index %}
    {%- endif %}
{%- endfor %}
{%- for message in messages %}
    {%- if message.content is string %}
        {%- set content = message.content %}
    {%- else %}
        {%- set content = '' %}
    {%- endif %}
    {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
        {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
    {%- elif message.role == "assistant" %}
        {%- set reasoning_content = '' %}
        {%- if message.reasoning_content is string %}
            {%- set reasoning_content = message.reasoning_content %}
        {%- else %}
            {%- if '</think>' in content %}
                {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
                {%- set content = content.split('</think>')[-1].lstrip('\n') %}
            {%- endif %}
        {%- endif %}
        {%- if loop.index0 > ns.last_query_index %}
            {%- if reasoning_content %}
                {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
            {%- else %}
                {{- '<|im_start|>' + message.role + '\n' + content }}
            {%- endif %}
        {%- else %}
            {{- '<|im_start|>' + message.role + '\n' + content }}
        {%- endif %}
        {%- if message.tool_calls %}
            {%- for tool_call in message.tool_calls %}
                {%- if (loop.first and content) or (not loop.first) %}
                    {{- '\n' }}
                {%- endif %}
                {%- if tool_call.function %}
                    {%- set tool_call = tool_call.function %}
                {%- endif %}
                {{- '<tool_call>\n{"name": "' }}
                {{- tool_call.name }}
                {{- '", "arguments": ' }}
                {%- if tool_call.arguments is string %}
                    {{- tool_call.arguments }}
                {%- else %}
                    {{- tool_call.arguments | tojson }}
                {%- endif %}
                {{- '}\n</tool_call>' }}
            {%- endfor %}
        {%- endif %}
        {{- '<|im_end|>\n' }}
    {%- elif message.role == "tool" %}
        {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
            {{- '<|im_start|>user' }}
        {%- endif %}
        {{- '\n<tool_response>\n' }}
        {{- content }}
        {{- '\n</tool_response>' }}
        {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
            {{- '<|im_end|>\n' }}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant\n' }}
{%- endif %}a   
FROM {__FILE_LOCATION__}
TEMPLATE """
{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end }}
{{- if or .System .Tools }}<|im_start|>system
{{ if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}

# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end -}}
<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if (and $.IsThinkSet (and .Thinking (or $last (gt $i $lastUserIdx)))) -}}
<think>{{ .Thinking }}</think>
{{ end -}}
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ end }}
{{- end }}
"""
zqwen3-instructa  {%- if tools %}
    {{- '<|im_start|>system\n' }}
    {%- if messages[0].role == 'system' %}
        {{- messages[0].content + '\n\n' }}
    {%- endif %}
    {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
    {%- for tool in tools %}
        {{- "\n" }}
        {{- tool | tojson }}
    {%- endfor %}
    {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
    {%- if messages[0].role == 'system' %}
        {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
    {%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
    {%- set index = (messages|length - 1) - loop.index0 %}
    {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
        {%- set ns.multi_step_tool = false %}
        {%- set ns.last_query_index = index %}
    {%- endif %}
{%- endfor %}
{%- for message in messages %}
    {%- if message.content is string %}
        {%- set content = message.content %}
    {%- else %}
        {%- set content = '' %}
    {%- endif %}
    {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
        {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
    {%- elif message.role == "assistant" %}
        {%- set reasoning_content = '' %}
        {%- if message.reasoning_content is string %}
            {%- set reasoning_content = message.reasoning_content %}
        {%- else %}
            {%- if '</think>' in content %}
                {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
                {%- set content = content.split('</think>')[-1].lstrip('\n') %}
            {%- endif %}
        {%- endif %}
        {%- if loop.index0 > ns.last_query_index %}
            {%- if loop.last or (not loop.last and reasoning_content) %}
                {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
            {%- else %}
                {{- '<|im_start|>' + message.role + '\n' + content }}
            {%- endif %}
        {%- else %}
            {{- '<|im_start|>' + message.role + '\n' + content }}
        {%- endif %}
        {%- if message.tool_calls %}
            {%- for tool_call in message.tool_calls %}
                {%- if (loop.first and content) or (not loop.first) %}
                    {{- '\n' }}
                {%- endif %}
                {%- if tool_call.function %}
                    {%- set tool_call = tool_call.function %}
                {%- endif %}
                {{- '<tool_call>\n{"name": "' }}
                {{- tool_call.name }}
                {{- '", "arguments": ' }}
                {%- if tool_call.arguments is string %}
                    {{- tool_call.arguments }}
                {%- else %}
                    {{- tool_call.arguments | tojson }}
                {%- endif %}
                {{- '}\n</tool_call>' }}
            {%- endfor %}
        {%- endif %}
        {{- '<|im_end|>\n' }}
    {%- elif message.role == "tool" %}
        {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
            {{- '<|im_start|>user' }}
        {%- endif %}
        {{- '\n<tool_response>\n' }}
        {{- content }}
        {{- '\n</tool_response>' }}
        {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
            {{- '<|im_end|>\n' }}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant
<think>
' }}
{%- endif %}zqwen3-thinkingz
{{bos_token}}{% for message in messages %}{{'<|im_start|>' + message['role'] + '
' + message['content'] + '<|im_end|>' + '
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}zlfm-2z{{ bos_token }}
{%- for message in messages %}
    {{ 'GPT4 Correct ' + message['role'].title() + ': ' + message['content'] + '<|end_of_turn|>' }}
{%- endfor %}
{%- if add_generation_prompt %}
    {{ 'GPT4 Correct Assistant:' }}
{%- endif %}a  
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}GPT4 Correct System: {{ .System }}<|end_of_turn|>
{{ end }}{{ if .Prompt }}GPT4 Correct User: {{ .Prompt }}<|end_of_turn|>
{{ end }}GPT4 Correct Assistant: {{ .Response }}<|end_of_turn|>"""
PARAMETER stop "<|end_of_turn|>"
PARAMETER stop "GPT4 Correct User:"
PARAMETER stop "GPT4 Correct Assistant:"
PARAMETER stop "GPT4 Correct System:"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
z<|end_of_turn|>starlinga%  
{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '
' + message['content'] + '<|im_end|>' + '
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
' }}{% endif %}
z
FROM {__FILE_LOCATION__}
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ .Response }}<|im_end|>"""
z<|endoftext|>zyi-chattemplatetype_chat_templatesystem_messagec                 V   Sn[         R                  U S 5      nUc   Ub  [        R                  " SU S35        X4$ UcJ  [        R
                  " X05      S LnU(       a(  Uc  [        S5      e[        R                  " X2U 5      nXb4$ X4$ Ub  UOUn[        R                  " X7U 5      nXg4$ )Nz\{system_message\}z4Unsloth: You tried to change the system message for zi, but it doesn't have a default system message. You need to manually add the system message in your data.zCUnsloth: You need to provide a system message for custom templates.)DEFAULT_SYSTEM_MESSAGEgetr   warning_onceresearch
ValueErrorsub)r.   r/   r0   system_message_patterndefault_system_messagehas_placeholdernew_templatemessage_to_uses           P/home/james-whalen/.local/lib/python3.13/site-packages/unsloth/chat_templates.py_change_system_messager?   *  s    2 477;M:NQUV%%FGYFZ [L L
 '' !))$:ETQ% !fgg66"8(SL//'' (6'A^G]N660(KL''    rolecontentuser	assistantrA   rB   rC   rD   c                 .   [        U5      [        L d   eU nSnU R                  R                  R	                  S5      (       a
  US:X  a  SnSn[        U SS5      nU R                  nSn	S n
[        U5      [        [        4;   aC  US   R                  5       n
Uu  p[        U5      [        L d   e[        U5      [        L d   eS nGOq[        U5      [        L Ga>  UR                  5       n
[        U   u  ppU(       d	  U(       a  SnU(       d	  U(       a  Sn[        U5      [        [        4;   a  Uu  p[        U5      [        L d   eOS n[        U5      [        L d   eU(       d  GOUGb  U R                  R                  5       nSnUR                  5        Hx  u  nnUR!                  SU S35      nUR!                  SU S35      nUS:w  a  [#        U S	35        US
-  nO.US:X  a  [%        U S35      eUR'                  SU S3SU S35      nMz      U(       aV  XR)                  5       ;  aC  [*        R,                  " SU SU R.                   S35        UR'                  U R.                  U5      n U[1        U5      :w  au  U R                  R3                  U5      nU R4                  nUU R.                  :X  a  UnSn	 U(       a  U R                  UUUS9nOU R                  UUS9n [7        U UU5      n GO!GOU(       Ga  US:w  Ga  [*        R,                  " SU SU R.                   S35        [        U SS 5      n[        U SS 5      n[        U SS 5      n[        U SS 5      nU R                  R                  5       nX;   a9  SnUR'                  UU5      nUR'                  UU5      nUR'                  UU5      nOUR'                  UU5      n U R                  R3                  U5      nUU:X  a  UnSn	 U R                  UUUUUS9nUU0n[7        U UU5      n O [9        S[        R;                  5        35      eU(       a  UR	                  S5      (       d  SU-   nUR'                  SSUS   -   S-   5      R'                  SSUS   -   S-   5      R'                  SSUS    -   S-   5      R'                  S!SUS"   -   S-   5      n[=        S U S#9u  nn Xl        USSS S"S$.:w  a  S%U-   S&-   U-   S'-   nOUn[?        XU5      u  pXl         [        USS 5      n[        USS 5      n[        USS 5      n[        U SS 5      n[        U SS 5      n[        U SS 5      nUU:w  a  UU l!        UU:w  a  UU l"        U	(       d  UU:w  a  UU l        [G        U 5      n Xl$        X@l%        U $ )(NFGemmar   r#   Tis_fastr   "z is already a token. Skipping.r   z was not part of the tokenizer!zUnsloth: Will map z
 to EOS = .)tokenizer_objectr   	pad_token)rK   rL   r   	bos_tokenrL   	unk_tokenz<|:__TEMP//STOP//TOKEN__:|>)rK   rM   r   rN   rL   zRUnsloth: `chat_template` must be a tuple of (your_template, eos_token,) or one of
r"   z{{- bos_token }}r"   z'role''rA   z	'content'rB   z'user'rC   z'assistant'rD   )model	tokenizerrE   z{% if 'role' in messages[0] %}z
{% else %}{% endif %})&typebool	__class____name__
startswithgetattrpadding_sidelisttuplelowerstrCHAT_TEMPLATESdict
_tokenizerto_stritemscountprintRuntimeErrorreplacevaluesr   r4   r   lenfrom_strrL   fix_sentencepiece_tokenizer	TypeErrorkeysr   r?   chat_templaterM   rN   r   _ollama_modelfile_system_message) rR   rn   mappingmap_eos_tokenr0   old_tokenizerIS_GEMMAis_fast_tokenizerold_padding_sidesame_padding_tokenr/   	stop_wordollama_modelfileyes_map_eos_tokentoken_mappingstring_vocabskipped	old_token	new_token	old_count	new_countnew_tokenizerold_pad_tokenold_bos_tokenold_eos_tokenold_unk_tokentemporary_stop_tokennew_chat_template_new_pad_tokennew_bos_tokennew_unk_tokens                                    r>   r   r   K  sB    $&'&MH##..w77H$nm  	9e< --MtUn, +1-335#0 M"c)*)I#%&%	m		#*002HVWdHeE"3 !2DM ]EM	?tUn,'0$M&$./. MI#%&% ! & %//668LG(5(;(;(=$	9(..9+Q/?@	(..9+Q/?@	>YK'EFGqLG!^&)4S'TUU#/#7#7!I;a8HAi[XYJZ#[L )> i3G3G3I&I##&8:iNaNaMbbc$de+33I4G4GS#m,, ) 4 4 = =l K !* 3 3 I$7$77$-M)-& $-$7$7+8$-$1 %8 %M %.$7$7+8$1 %8 %M  8	=R_a		[ 8"4YKz)J]J]I^^_ `a $I{DAM#I{DAM#I{DAM#I{DAM$//668L('D$+33MCWX+33I}M+334H)T+33M9M%0099,GM - )%)"%//#0)%)) 0 M ,i:M3I}m]I a""$%'
 	
 001XYY)M9 &	gfo 5S @	A	gi&8 8S @	A	gfo 5S @	A	gk&: :S @	A	  #4YGLAy- F	FZeff,  	 	 *$:=^l$m!M+ M;=MM;=MM;=MI;=MI;=MI;=M%]y':%]y':M)9+>
 'y1I #3"0r@   c                 v    UR                  U R                  5      (       a  U[        U R                  5      S  nU$ N)rX   rM   ri   )rR   prompts     r>   r   r   0	  s6    ,,--I//012Mr@   c           	         [         R                  " SU 5      n[        UR                  5      nU H"  nXC;  d  M
  [	        SU S[        U5       35      e   [        [         R                  " SU [         R                  [         R                  -  S95      nU Vs/ s H#  ofR                  5       UR                  S5      4PM%     nn/ n[        U5      S:w  a  US   nUS   S   n	U	S:w  a  UR                  U S U	 5        [        US S USS  5       H?  u  pUS   S   U
S   S   pUR                  U5        X:w  d  M,  UR                  X	U 5        MA     UR                  US   5        US   n
U
S   S   nU[        U 5      :w  a  UR                  XS  5        OUR                  U 5        S	R                  S
 U 5       5      nX:X  d   eX'4$ s  snf )N	\{(.+?)\}zUnsloth: Your prompt includes 'zC' but this does not exist in the dataset. Only allowed columns are z\[\[.+?\]\]flagsr   r   r'   c              3   T   #    U  H  n[        U5      [        L a  UOUS    v   M      g7f)r   N)rT   r^   .0xs     r>   	<genexpr>)_parse_combined_prompt.<locals>.<genexpr>\	  s%     [DZq$q'S.Qad:DZs   &()r5   findallsetcolumn_namesKeyErrorr[   finditerDOTALL	MULTILINEspangroupri   appendzipjoin)combined_promptdatasetpossible_columnsdataset_columnscolumnoptional_promptsr   final_optional_promptsleftlrightrcheck_combineds                r>   _parse_combined_promptr   7	  s   zz,@'../O"(1& :,,0,A+BD  # BKKQSQZQZ]_]i]iQijk8HI8H11771:.8HI
!"GAJ6)00!1DE /46Fqr6JKKD72;aq"))$/v-44_5KL L 	%%&6r&:; !$!HQKO$$&<&C&COTVDW&X 	%%o6WW[DZ[[N,-,337 Js   *Gc           
         S/n[        [        U 5      5      nU H  nUR                  S U SU S35        M     UR                  S S35        UR                  S SSR                  U5       SSR                  S	 U 5       5       S
35        Sn/ n[	        U5       GH1  u  p[        U	5      [        L a_  [        R                  " SU	5      nXt-  nXiR                  S5      R                  S5      R                  SS5      R                  SS5      -  nMw  U	u  pUSS R                  S5      R                  S5      R                  SS5      R                  SS5      n[        R                  " SU5      nSU S3nS U SU SSR                  S U 5       5       SUS    S3	nUR                  U5        UR                  U5        USU-   S-   -  nGM4     UR                  S S S!U S35        UR                  S S"SR                  S# U 5       5       S$35        UR                  S S%3S&-   SU S'3-   S(-   5        S)R                  U5      $ )*Nz,def __combined_prompt_processor__(examples):    z__ = examples['z']z
texts = []for (, 	) in zip(c              3   *   #    U  H	  o S 3v   M     g7f)__N r   s     r>   r   $_create_formatter.<locals>.<genexpr>i	  s     Id\cWXCr(\cs   z):r'   r   zunicode-escapeutf-8rP   z\'rI   z\"   __optional_r           z = 'z	'.format(c              3   .   #    U  H  o S U 3v   M     g7fz = Nr   r   s     r>   r   r   |	  s     @_W^RS3c!W^   z) if r   z else ''{}r   z__combined_prompt__ = 'z(texts.append(__combined_prompt__.format(c              3   .   #    U  H  o S U 3v   M     g7fr   r   r   s     r>   r   r   	  s     ;\R[QcQCLR[r   z))return { z	' : texts }
)r[   r   r   r   	enumeraterT   r^   r5   r   encodedecoderg   insert)r   r   user_column_namefunctioncolumnsr   final_prompt	formatterjoptional_promptwherer   r   s                r>   _create_formatterr   b	  sq   >?H3'()G5'&CD OOugZ()OOugU499W#5"6i		Id\cId@d?eeghi LI'(>? C'jj?G I223CDKKGT\\]`bghppqtv{||L+ME Ab\(()9:AA'JRRSVX]^ffgjlqrFjjv6GaS#AwqcfXYtyy@_W^@_7_6``efmnofpeqqyzFOOF#QC!GcM)L! @$ OOA% 7~QGHOOug 226));\R[;\2\1]]_a bOOugW%,3C2DI/NNQUUV99Xr@   c                 B  ^^ SU R                   ;   a%  U S   S   n[        U5      [        L a  [        S5      e[	        X5      u  p[        XT5      n
[        U
[        5       5        U R                  [        SSS9n UU4S jnU R                  USSU(       a  U R                   OS	S
9n SSK
Jn  [        US-
  S5      nUS:X  a  U $ U R                  SS05      n U /n[        SUS-   5       H9  nU R                  Xo-   S9R                  SSU 305      nUR!                  U5        M;     U" USS9n Sn
US-  n[        U5       H  nU
S SU SU S3-  n
M     U
S S3-  n
U
S SSR#                  S [        U5       5       5       SSR#                  S [        U5       5       5       S3-  n
U
S SSR#                  S [        U5       5       5       S3-  n
U
S S 3S!-   S"-   S#-   -  n
[        U
[        5       5        U R                  [$        SS$U(       a  U R                   OS	S
9n U $ )%a  
Converts a dataset to ShareGPT style.
ShareGPT requires only 1 input and 1 output field.
This means one has to merge multiple columns into 1 for 1 input field.
Use `conversation_extension` to increase the length of each conversation by randomnly
selecting a few and packing them into 1.

merged_prompt = "",                 Prompt to merge columns into 1 input
merged_column_name = "instruction", Final column name for the input  field
output_column_name = "output",      Final column name for the output field
remove_unused_columns = True,
conversation_extension = 1,         Automatically combines `conversation_extension` convos into 1
random_state = 3407,
conversationsr   z=Unsloth: Your dataset is probably already in ShareGPT format!TzMerging columns)batcheddescc           	         > U T   nU T   n[        X5       VVs/ s H!  u  p4S[        U5      S.S[        U5      S./PM#     nnnSU0$ s  snnf )Nhuman)fromvaluegptr   )r   r^   )examplesusers
assistantsrC   rD   textsmerged_column_nameoutput_column_names         r>   __convert_to_sharegpt__,to_sharegpt.<locals>.__convert_to_sharegpt__	  sr    0101
 $'u#9

 $: "SY<S^< $: 	 
 !5++
s   (A	zConverting to ShareGPTN)r   r   remove_columns)concatenate_datasetsr   conversations0)seed)axisz)def __combine_conversations__(examples):
r   z__ = examples['conversationsz']
zconvos = []
r   r   c              3   ,   #    U  H
  nS U 3v   M     g7fr   Nr   r   r   s     r>   r   to_sharegpt.<locals>.<genexpr>	  s     (ZFY=)<FY   r   c              3   .   #    U  H  nS U S3v   M     g7f)r   r   Nr   r   s     r>   r   r   	  s     #WCVamA3b$9CVr   z):
r   zconvos.append(+c              3   ,   #    U  H
  nS U 3v   M     g7fr   r   r   s     r>   r   r   	  s     M9LAmA3/9Lr   z)
r   r   z'conversations' : convosr   zExtending conversations)r   rT   r[   rl   r   r   execglobalsmap__combined_prompt_processor__datasetsr   maxrename_columnsrangeshuffler   r   __combine_conversations__)r   merged_promptr   r   remove_unused_columnsconversation_extensionrandom_stateconvor   r   r   r   r   n_extensionsall_shuffledr   shuffleds     ``             r>   r   r   	  sy   . '...
?+;$[\\/Em/], !1K]^H79kk74PakbG
, kk'1F--D  G .-a/3Lq.$$o8H%IJG9L1l1n%??,.?9HHJZ_lmnlo]pIqrH% & #<:G <HAL< ug]1#-I!DQQ !5'''H5'tyy(ZeLFY(ZZ[ \))#W5CV#WWXX\^ ^H5'88M|9LMMNcS SH5'!D(+EELLH 	79kk!(1F--D  G Nr@   c                 T   U R                   R                  5       nU Vs/ s H  n[        U5      PM     nn[        [	        U5      [	        U5      -
  5      n[        U SS 5      b#  U Vs/ s H  o3U R                  :w  d  M  UPM     nn/ nSR                  U5      nU H  n[        U5      nUR                  US US-   5      nUS:  d  M-  [        US-  S-   U5       HL  n	UR                  US U	 5      U:  d  M  U	S-  n	UR                  US U	 S5      nUR                  US U	 5          M     M     UR                  S5      n
[        X*5       VVs/ s H  u  pX:X  d  M  UPM     nnnX-  nX-  n/ nU H  nUR                  S5      [        U5      :X  a  M#  UR                  S5      [        U5      :X  a  MC  UR                  S5      (       a  [        U5      S::  a  Mj  UR                  S	5      (       a  [        U5      S
:X  a  M  UR                  U5        M     U$ s  snf s  snf s  snnf )NrM   z r   r   r'   r   u   ▁<z</   )added_tokens_decoderrh   r^   r[   r   rY   rM   r   ri   rd   r   rg   r   splitr   rX   )rR   extra_eos_tokensr  r   repeatted_tokensjoined_texttokennrepeatted_countsr   splittedoldnewfinal_eos_tokensfiltered_eos_tokenss                  r>   get_ollama_eos_tokensr  	  s'   $99@@B,@A,@qCF,@A  $8 9C@P<Q QR y+t,8+?\+?a	H[H[C[+?\//"67K%J&,,U5AqD\: a1a461%$$U2AY/2BBFA"-"5"5eBQi"DK$++E"1I6 & &   ,H,/0D,O^,OSVS],O^(( ![[#e*,h[[3u:-xc""s5zQd##E
a""5) " Q B  ]* _s   H(H?HH$H$c           
         UR                  5       nU c   eUc  / nO[        U5      [        L a  U/nU R                  5       nU H+  n[        U5      [        L d   eXT;  d  M  [	        SU S35      e   SnU R
                  b  UR                  SU R
                  5        [        U5      S:X  a  [        S5      eU R                  R                  5       nUR                  S5      (       a  UR                  S5        O8SU;   d  SU;   a,  UR                  S	5      (       a  [        R                  " S
5        [        [!        U5      5      nSnU H=  n	U[        ["        R$                  " S["        R&                  " U	5      -   U5      5      -  nM?     Sn
 [        U5      S-
  nSnUS:  a+  UR)                  XS SU5      nUS:X  a  OUS-  nSnUS:  a  M+  US:  a  US-  nO[        U5      eU(       d  [        U5      eSn
XS nUR+                  S5      S:w  d  UR+                  S5      S:w  a  [        U5      eUSU nXS nU
(       a  UOUn
SR-                  S U 5       5      n[        U5      S:w  a  SU S3nOSnSU-   n[        ["        R.                  " UU5      5      n[        U5      S:X  d   eUS   nUR1                  S5      S   nUSU nUUS nUR3                  U5      nUSUS:w  a  UO
[        U5       nUU-   U-   nUU
:w  a5  UR5                  SS5      nU
R5                  SS5      n[        SU SU 35      e US:X  a   [        R                  " S 5        US   n	UU	-   nUn$Sn%Sn&U " S!5      R@                  S   [C        U S"S5      :X  a<  Sn&U$R                  U RD                  5      (       a  Sn%U$[        U RD                  5      S n$S#U$;   a  S$U$R5                  S#S%5      -   S&-   n'OU$n'S'UR5                  SS(5      -   S&-   n(UR5                  SS)5      n)[G        X5      n*SR-                  S* U* 5       5      n*U*S+-  n*S,n+S-U+-   U'-   U(-   U)-   U+-   S.-   U*-   n,SDS/ jn-U-" US5      n.U-" US5      n/S0U.-   S1-   U/-   S2-   USUR3                  S5       -   S3-   n0[        U5      S:w  a  U-" US#S45      n1U1R5                  S#S5      n1S#U1;   a  Uc  [        S55      eU%(       a:  U1R5                  U RD                  SS5      n1UR5                  U RD                  SS5      nS6U1-   S7-   n1Ub/  UR5                  S#U5      n2S#U;   a  U,S8U-   S9-   -  n,U1S:U2-   S;-   -  n1OU1S<-  n1U1U0-   n0U%(       a  S=U0-   n0S>U0;  a  U0R5                  S?S@S5      n0["        RH                  " SASBU0["        R8                  ["        R6                  -  S9n0U&(       a  U0R                  SC5      (       d  S=U0-   n0USUR3                  S5       nUSUR3                  S5       nU,U0UU4$ !   XR3                  S5      [        S5      -   S n["        R&                  " U5      nSU-   S-   U-   S-   n["        R$                  " UU["        R6                  ["        R8                  -  S9nUS   n[;        S[        U5      5       Hh  n["        R&                  " USU 5      n[=        ["        R.                  " SU-   S-   U["        R6                  ["        R8                  -  S95      nMb  !      O= f   WR?                  S5      nUR3                  U5      n USU  R)                  U5      n!U!S:X  a  Sn!UU!U  n"U"U-   nUR3                  U5      n#USU# nUU"Unnn GN+= f)E
Creates an Ollama modelfile and a HF Jinja template from a custom
template. You must provide 2x examples of an input & output.
There is an optional system message as well.

You must use {INPUT}, {OUTPUT} twice, and {SYSTEM} is optional.
Nz
Unsloth: `z+` is not a singular token in the tokenizer.aP  Unsloth: Your prompt template must have 2 examples showing the user input {INPUT} and the assistant output {OUTPUT}

For example what is not allowed is just:
### Input:\n{INPUT}\n\n### Response:\n{OUTPUT}\n

What is required is 2x of this:
### Input:\n{INPUT}\n\n### Response:\n{OUTPUT}\n### Input:\n{INPUT}\n\n### Response:\n{OUTPUT}\nr   z\Unsloth: Your tokenizer does not have an EOS token? Please provide one via extra_eos_tokens!)zunsloth/llama-3-8b-instructzunsloth/llama-3-70b-instructz
<|eot_id|>)zunsloth/llama-3-8bzunsloth/llama-3-70bzmUnsloth: Base llama-3 models did not train <|eot_id|>.
Please use the instruct version or use <|end_of_text|>z{OUTPUT}Fr   r   Tz{INPUT}|c              3   V   #    U  H  nS [         R                  " U5       S3v   M!     g7f)(?:)N)r5   escaper   s     r>   r   *construct_chat_template.<locals>.<genexpr>|
  s#     )ZIYAC		!~Q*?IYs   ')r  z)?r'   z\{INPUT\}[\s\n]{0,}r   z\nzCUnsloth: The prompt template you provided isn't correct. You gave:
z 

But we require the following:
z(.+?{OUTPUT}r  r   (z).+?\{INPUT\}zIUnsloth: We automatically added an EOS token to stop endless generations.Abos_token_idz{SYSTEM}z{{ if .System }}z{{ .System }}z	{{ end }}z{{ if .Prompt }}z{{ .Prompt }}z{{ .Response }}c              3   .   #    U  H  nS U S3v   M     g7f)zPARAMETER stop "rI   Nr   )r   eoss     r>   r   r!  
  s     K
-cU!4
r   z.
PARAMETER temperature 1.5
PARAMETER min_p 0.1z"""z#FROM {__FILE_LOCATION__}

TEMPLATE z

c                 B   U R                  U5      (       a  SU S U R                  U5       -   SU 3-   n OOU R                  U5      (       a  U S3X R                  U5      S  -   S-   n OSU R                  USU S35      -   S-   n U R                  S5      (       a  U SS  n U $ )NrP   z' + z + 'z'' +    )endswithfindrX   rg   )partwhichrB   s      r>   process(construct_chat_template.<locals>.process
  s    ==/tyy/00T'3CCD__U##Yd#d99U+;+<&==CDetG9D-ABBSHD??7##DHTr@   zG{% for message in loop_messages %}{% if message['role'] == 'user' %}{{ z/ }}{% elif message['role'] == 'assistant' %}{{ z }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'z' }}{% endif %}zmessages[0]['content']z1Unsloth: Please specify a default system message!z+{% if messages[0]['role'] == 'system' %}{{ z) }}{% set loop_messages = messages[1:] %}z	
SYSTEM "rI   z{% else %}{{ 'z1' }}{% set loop_messages = messages %}{% endif %}rS   r"   z"{% set loop_messages = messages %}z"{% for message in loop_messages %}z{% for message in messages %}z\{\% if messages\[0\]\['role'\] \=\= 'system' \%\}\{\{ '(.+?)' \}\}\{\% set loop\_messages \= messages\[1\:\] \%\}\{\% else \%\}\{\{ '\1' \}\}\{\% set loop\_messages \= messages \%\}\{\% endif \%\}\{\% for message in loop\_messages \%\}z'{{ '\1' }}{% for message in messages %}rO   )zmessage['content'])%lstriprT   r^   	get_vocabr7   r   r   ri   rf   name_or_pathr]   rX   r   r   warningr[   r   r5   r   r   rfindrd   r   r   r   r*  rg   r   r   r   nextr   	input_idsrY   rM   r  r8   )3rR   rn   r:   r  vocab	extra_eos	error_msgtokenizer_name	count_eosr&  final_combined_checkr   at_least_onefoundinstruction_responser   r   extra_eos_tokens_regexfind_end	input_end
input_partoutput_partwhere_systemsystem_partcombinedcombined_changedleft_changedending	find_textresponse_parttry_find	separatorresponse_startstart_instructioninstruction_partr   ollama_systemhas_bos_tokenalways_bos_tokensystem_modelfileinput_modelfileoutput_modelfile
ollama_eosr+  	modelfiler-  input_jinjaoutput_jinjajinja_templatepartial_systemfull_systems3                                                      r>   construct_chat_templater^  
  s   : "((*M ! B!1		3	&<L;N(8!E%	I#%&%!z)4_`aa &	@  &9#6#67
!j
 	

 ++113N  !`aa-
*
*lm.K!!"OPPE	
 C 012ISK"))C.$@-PQQ	   !S\q !e!''b(91a@E{EFAL	 !e
 q5!q&! ++<	#::  $  -R0%%i0A59M9S9ST^9_cd9dy)) bq!b!';t "%)ZIY)Z!Z%&!+34B7HH)H4Xu56	9~"#"aL	NN1%a(	:I&
 IJ' yy,MLB,>LCIN +k9++';;D%H3;;D%HLV#$ %2."  ,D A~bcq!!C'
  MM~"gi&NN##I$7$788 M)#i.A.A*B*CDM]"-0E0EjRa0bbepp()J,?,?	O,\\_jjO"**:7HI 'yCJK
KKJ DDJ D)*,;<>NO"#I
 :	2K;
3L	#	$'	 %		%(	
	 !!>+"2"2:">?
	@C	  ;1 j:RS'//
B?'%-"#VWW +33I4G4GQON(33I4G4GQOK&'*99 	 "-%--j:PQK[(\,BBSHH	 $%( N
 m+N'.8.?N ,>A'//0+
 VV	3 	3ryy 8N (()PQQ.?N :z//	:;J;{//
;<Knj+==k\11*=JOPQ6"&7&@3F	

9mRYYQSQ]Q]E]^%a(q#m,-Ayyr!23Hbkk#.;L*Lmegenenqsq}q}e}~E . KKN	&++M:)/>:@@K"$5():>J#m3""8,#FU+/:<LmZs.   ?W> E+W> >B0]%.A[42]%4[96A,]%c                      Sn SSK Jn  UR                  SU S9nSnSnS n[        UUUS9u  pg  nS	S
S.SSS.SSS.SSS.SSS.SSS./n	UR	                  U	SSS9n
Xrl        UR	                  U	SSS9nX:X  d   eg )Nhf_r   AutoTokenizerz#meta-llama/Meta-Llama-3-8B-Instruct)r  G  <|begin_of_text|><|start_header_id|>system<|end_header_id|>

{SYSTEM}<|eot_id|><|start_header_id|>user<|end_header_id|>

{INPUT}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{OUTPUT}<|eot_id|><|start_header_id|>user<|end_header_id|>

{INPUT}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{OUTPUT}<|eot_id|>r    )rR   rn   r  systemzYou are an assistantrA   rB   rC   What is 2+2?rD   It's 4.zOk!zAnything else?zWhat's 2x2?FTtokenizeadd_generation_prompt)transformersrb  from_pretrainedr^  r	   rn   )r  rb  rR   rn   r:   r  rX  r[  r   messagescorrect_output
new_outputs               r>   r   r   2  s    E*--.S]b-cI
M 	z  &=%+'#Iq! &<=N33E*)9:M2H 228gk2lN,..xEcg.hJ'('r@   c                 0  ^ [        TUUUS9u  pVpxU4S jn	UTl        UTl        UTl        UTl        [        TS5      (       aD  UTR                  l        UTR                  l        UTR                  l        UTR                  l        U R                  U	SS9$ )r  )rR   rn   r:   r  c           	      b   > U S   nU Vs/ s H  nTR                  USSS9PM     nnSU0$ s  snf )Nr   Frh  text)r	   )r   convosr  r   rR   s       r>   formatting_prompts_func4apply_chat_template.<locals>.formatting_prompts_func  sH    /*tz{tzkp..u`e.ftz{%"" |s   ,rR   T)r   )r^  rn   ro   _unsloth_input_part_unsloth_output_parthasattrrR   r   )
r   rR   rn   r:   r  rX  r[  rB  rC  rt  s
    `        r>   r	   r	   ]  s    < :Q%!7+	:6Iz#
 -I"+I%/I!%0I"y+&&,:	)09	-3=	/3>	0;;.$;@@r@   c                 L   ^   " U 4S jS[         5      n[        U" US9/5      nU$ )Nc                   J   >^  \ rS rSrSrS	U U4S jjrS\S\S\4S jr	Sr
U =r$ )
5create_stopping_criteria.<locals>.StoppingCriteriaSubi  )
stop_tokensingle_matchlengthc                   > [         TU ]  5         US:X  a+  [        R                  TR                  SS9U l        SU l        OjT" SU-   /SSS9U l        U R
                  R                  R                  5       SS  R                  S5      U l        U R
                  R                  S	   U l        U R                  S:H  U l        g )
Nr   cuda)devicer   r   Fpt)add_special_tokensreturn_tensorsr   )super__init__torchtensoreos_token_idr|  r~  r5  raveltoshaper}  )selfstopsr  
encountersrV   rR   s       r>   r  >create_stopping_criteria.<locals>.StoppingCriteriaSub.__init__  s    G#"',,y/E/EPV,"W"+TE\NQVim"n"&//";";"A"A"CAB"G"J"J6"R"oo33A6 $q 0Dr@   r5  scoresreturnc                 
   UR                  5       nUS   nU R                  (       a  X0R                  :X  a  gUR                  S   U R                  :  a0  XR                  * S  U R                  :H  R                  5       (       a  gg)Nr   Tr   F)r  r}  r|  r  r~  all)r  r5  r  
last_tokens       r>   __call__>create_stopping_criteria.<locals>.StoppingCriteriaSub.__call__  sh    !)I"2J  jOO&CTq!T[[0KK<=)T__<AACCDr@   )r~  r}  r|  )r   r  r   )rW   
__module____qualname____firstlineno__	__slots__r  r   r   rU   r  __static_attributes____classcell__)rV   rR   s   @r>   StoppingCriteriaSubr{    s1    ;			1 		1	j 	+ 	$ 	 	r@   r  )r  r   )rR   rx   r  stopping_criterias   `   r>   create_stopping_criteriar    s,    . , -.A).T-UVr@   c                  2   SSS.SSS.SSS.SSS.SS	S.SS
S./n SSK Jn  [        nUR                  S5      nUR	                  U SSS9nX#l        UR	                  U SSS9nXE:X  d   e[        nUR                  S5      nUR	                  U SSS9nX#l        UR	                  U SSS9nXE:X  d   e[        nUR                  S5      nUR	                  U SS  SSS9nX#l        UR	                  U SS  SSS9nXE:X  d   e[        nUR                  S5      nUR	                  U SSS9nX#l        UR	                  U SSS9nXE:X  d   e SSK	J
n  U" S5      n[        [        U 5      S-
  5       H0  nUR                  UR                   US-  S:H     XS-      S   5        M2     UR                  UR                   S   S5        ["        R$                  UR'                  5       -   n[(        nUR                  S5      nX#l        UR	                  U SS  SSS9nXE:X  d   e SSK	J
n  U" S5      n[        [        U 5      S-
  5       H0  nUR                  UR                   US-  S:H     XS-      S   5        M2     UR                  UR                   S   S5        ["        R$                  UR'                  5       -   n[*        nUR                  S5      nX#l        UR	                  U SS  SSS9nXER-                  SS5      :X  d   eUR                  S5      nUR	                  U SS  SSS9n[.        Ul        UR	                  U SS  SSS9nXT:X  d   e[0        nUR                  S5      nUR	                  U SSS9nX#l        UR	                  U SSS9nXE:X  d   e[2        nUR                  S 5      nUR	                  U SS  SSS9nX#l        UR	                  U SS  SSS9nXE:X  d   eg !   [        R                  " S5        SSK	J
n   GN= f!   [        R                  " S5        SSK	J
n   GN= f)!Nrd  z You are a friendly chatbot.re  rC   rf  rD   rg    But 2+2 is equal to 5. No I'm sure its 4.  No it's 100% 5! r   ra  zHuggingFaceH4/zephyr-7b-betaFTrh  z!teknium/OpenHermes-2.5-Mistral-7Bz"mistralai/Mistral-7B-Instruct-v0.2r   zunsloth/llama-2-7b-chat)get_conv_templatez;pip -qqq install git+https://github.com/lm-sys/FastChat.gitzvicuna_v1.1r   rB   r'   zlmsys/vicuna-7b-v1.5	zero_shotz</s>zunsloth/gemma-7b-itzunsloth/llama-3-8b-Instructz microsoft/Phi-3-mini-4k-instruct)rk  rb  zephyr_templaterl  r	   rn   chatml_templatemistral_templatellama_templatefastchat.conversationr  osrd  r   ri   append_messagerolesrR   rM   
get_promptvicuna_templatevicuna_old_templaterg   gemma_templatellama3_templatephi3_template)rm  rb  r.   correct_tokenizercorrect_prompt
our_promptr  r   s           r>   r   r     s   %CEN33$?@)=>$89H +H%556TU&::8PUos:tN&.#"66xEko6pJ'(' H%556YZ&::8PUos:tN&.#"66xEko6pJ'('  H%556Z[&::8AB<TYsw:xN&.#"66x|PUos6tJ'(' H%556OP&::8PUos:tN&.#"66xEko6pJ'('<; '}5N3x=?#%%n&:&:1Q36&BHqSMR[D\] $!!."6"6q"92>((>+D+D+FFNH%556LM&.#"66x|PUos6tJ'('<; '{3N3x=?#%%n&:&:1Q36&BHqSMR[D\] $!!."6"6q"92>((>+D+D+FFN"H%556LM&.#"66x|PUos6tJ//;;<; &556KL&::8AB<TYsw:xN&4#"66x|PUos6tJ'(' H%556ST&::8PUos:tN&.#"66xEko6pJ'(' H%556XY&::8AB<TYsw:xN&.#"66x|PUos6tJ'('m<
		OP;;<
		OP;;s    O O5 O25Pc           
      <   SSK nSSKnSSS.SSS.SSS.SS	S.SS
S./nSR                  SSS5      nU/nU R                  b?  U R	                  USSS9nUR                  SS5      n[        X5      nUR                  U5        U GH~  nSU SU S3n/ nUR                  USUR                  UR                  SS9 n	U	R                   H"  n
UR                  U
R                  SSS95        M$     SSS5        SR                  U5      nUR                  " SXR                  S9nU Vs/ s H  n[!        US   5      US   4PM     nnU " U5      R"                  nU R%                  U5      n['        [)        X5      5      n[+        [)        UU5      5       Hn  u  nu  nnUS   US   :w  d  M  [-        SU5        [-        SU5        [-        SU5        [-        U5        [-        5         [-        U5        [-        5         [/        S5      e   GM     g! , (       d  f       GN"= fs  snf ) z]
Carefully checks the output of GGUF's tokenization and HF.
Can catch all tokenization bugs.
r   NrC   rf  re  rD   rg  r  r  r  zBelow is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

    ### Instruction:
    {}

    ### Input:
    {}

    ### Response:
    {}z#Describe the city given eloquently.zThe lost city of Atlantis.r'   FTrh  rP   z./llama.cpp/llama-cli -m z6 -n 0 --temp 0.0 --verbose-prompt --check-tensors -p 'r   )shellstdoutstderrbufsizer   rg   )errorsz([\d]{1,}) \-\> \'([^\']{1,})\'r   zFailed GGUF != HF atzHF =zGGUF =zFailed comparing GGUF to HF.)
subprocessr5   formatrn   r	   rg   r   r   PopenPIPESTDOUTr  r   r   r   r   intr5  batch_decoder[   r   r   re   rf   )rR   
gguf_modelr  r5   rm  r   promptscommanddatassplinegguf_tokensgguf_tokenizedr   r5  tokenshf_tokenizedr   hf_token
gguf_tokens                       r>   r   r     s6   
 N33$?@)=>$89H	
 &-$
  kG*..xEcg.hR(&y9v-j\ :##)(!- gtjooXbXiXiuvw{}		T[[9[EF " x ggen $F]i]ij6DEn3qt9ad,nEf%//	''	2C	23 *33|^3T)U%A%*z!},,a0fh'h
+l#n%"#ABB *V' : 1 xw Fs   93H$H
H	r   )r'   instructionoutputTr   iO  )Nrc  r    N)r   )z./model-unsloth.F16.gguf)q__all__rk  r   r   r  r   r   (transformers.models.llama.modeling_llamar   saver   r  shutiltokenizer_utilsmodels._utilsr   r5   unsloth_zoo.dataset_utilsr
   r   r   r_   r2   unsloth_templateunsloth_ollamaunsloth_eos_tokenr  zephyr_ollamazephyr_eos_tokenr  chatml_ollamachatml_eos_tokenr  mistral_ollamamistral_eos_tokenr  llama_ollamallama_eos_tokenr  vicuna_ollamavicuna_eos_tokenr  vicuna_old_ollamavicuna_old_eos_tokenalpaca_templatealpaca_ollamaalpaca_eos_tokenr  gemma_ollamagemma_eos_tokengemma_chatml_templategemma_chatml_ollamagemma_chatml_eos_tokengemma2_templategemma2_ollamagemma2_eos_tokengemma2_chatml_templategemma2_chatml_ollamagemma2_chatml_eos_tokenr  llama3_ollamallama3_template_eos_tokenr  phi3_ollamaphi3_template_eos_tokenllama31_templatellama31_ollamallama31_template_eos_tokenversionqwen25_templateqwen25_ollamaqwen25_template_eos_tokenqwen25_default_system_messagephi4_template_phi4_ollama_templatephi4_ollamaphi4_template_eos_tokengemma3_templategemma3_ollamagemma3_template_eos_tokenqwen3_templateqwen3_ollamaqwen3_template_eos_tokengemma3n_templategemma3n_ollamagemma3n_template_eos_tokengptoss_templategptoss_ollama"gptoss_template_template_eos_tokenqwen3_instruct_templateqwen3_thinking_templateliquid_lfm2_templateliquid_lfm2_template_eos_tokenstarling_templatestarling_ollamastarling_template_eos_tokenyi_chat_templateyi_chat_ollamayi_chat_template_eos_tokenr^   r?   r   r   r   r   r   r  r^  r   r	   r  r   r   r   r@   r>   <module>r     s   @ ) ; ( 	   * 	 0  
 .
    -/@%Yy $M y !
    +-=umUx #' x  
      +-=t]Tx #' x  
 2    -/@%Yy $( y !
 0  )?E<Qw "& w 
 0   +-=umUx  $@ x  
 .
  #  35I5Rce|  (H | $-l;| '=l'K | $
 . $  +-=umUx  $U x   *   ")?D,Pw "& w  *O;  & (<@  #89OQUWj!l~ )- ~ &
 !99" +-=t]Tx #' x   / *-GG 0 #9;RTXZn"p *.  '
 " " ( ,.GP]_y $( y !+-F}^x #' x     " $ *,CUKYw "& w *73x #' x  *73y $( y !"m d9 x ) /1KUTbd{ &( { #/1KUTbdz %' z "AG,[9N7&(7# B0 l8 v (  f -/H%Q^`z %B z "-/H%Q^`y $A y !-/H%Q^`x #@ x  -/H%Q^`y $A y !
 C "# $  ' (*A5+Ww "& w ( Z . , ,.GP]_y $( y !+-F}^x #' x  
c P; | ( *,De\[x #' x  )+CULZw "& w * ^   - .0JESacz %) z "-/I5R`by $( y ![ @r j &2 ",.PRWYfhy $( y !+-OQVXegx #' x  U t6 r ( $;=UW\^j#l  +/ ' (
U p %<=UW\^j#l  +/ ' (
  ". /1OQVX\]w "& w    0 /1LeUdez %) z "   - -/I5R`ay $( y !(S (c (SV (F IVabbJ(4V#P &! Vr 9; *^ 
 v'a>H	()\ 
 v)3Al6d)NBr@   