Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {#- Unsloth template fixes #}
- {%- set yesterday_day = strftime_now("%d") %}
- {%- set yesterday_month = strftime_now("%m") %}
- {%- set yesterday_year = strftime_now("%Y") %}
- {%- set today_date = yesterday_year + '-' + yesterday_month + '-' + yesterday_day %}
- {%- if yesterday_day == '01' %}
- {#- Jinja doesnt allow minus 1 date - Unsloth alternative #}
- {%- if yesterday_month == '01' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '12' %}
- {%- if yesterday_year == '2024' %}
- {%- set yesterday_year = '2023' %}
- {%- elif yesterday_year == '2025' %}
- {%- set yesterday_year = '2024' %}
- {%- elif yesterday_year == '2026' %}
- {%- set yesterday_year = '2025' %}
- {%- elif yesterday_year == '2027' %}
- {%- set yesterday_year = '2026' %}
- {%- elif yesterday_year == '2028' %}
- {%- set yesterday_year = '2027' %}
- {%- elif yesterday_year == '2029' %}
- {%- set yesterday_year = '2028' %}
- {%- elif yesterday_year == '2030' %}
- {%- set yesterday_year = '2029' %}
- {%- elif yesterday_year == '2031' %}
- {%- set yesterday_year = '2030' %}
- {%- elif yesterday_year == '2032' %}
- {%- set yesterday_year = '2031' %}
- {%- elif yesterday_year == '1970' %}
- {#- Stop llama_cpp from erroring out #}
- {%- set yesterday_year = '1970' %}
- {%- else %}
- {{- raise_exception('Unsloth custom template does not support years > 2032. Error year = [' + yesterday_year + ']') }}
- {%- endif %}
- {%- elif yesterday_month == '02' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '01' %}
- {%- elif yesterday_month == '03' %}
- {%- set yesterday_month = '02' %}
- {%- set yesterday_day = '28' %}
- {%- if yesterday_year == '2024' %}
- {%- set yesterday_day = '29' %}
- {%- elif yesterday_year == '2028' %}
- {%- set yesterday_day = '29' %}
- {%- elif yesterday_year == '2032' %}
- {%- set yesterday_day = '29' %}
- {%- elif yesterday_year == '1970' %}
- {#- Stop llama_cpp from erroring out #}
- {%- set yesterday_day = '29' %}
- {%- else %}
- {{- raise_exception('Unsloth custom template does not support years > 2032. Error year = [' + yesterday_year + ']') }}
- {%- endif %}
- {%- elif yesterday_month == '04' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '03' %}
- {%- elif yesterday_month == '05' %}
- {%- set yesterday_day = '30' %}
- {%- set yesterday_month = '04' %}
- {%- elif yesterday_month == '06' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '05' %}
- {%- elif yesterday_month == '07' %}
- {%- set yesterday_day = '30' %}
- {%- set yesterday_month = '06' %}
- {%- elif yesterday_month == '08' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '07' %}
- {%- elif yesterday_month == '09' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '08' %}
- {%- elif yesterday_month == '10' %}
- {%- set yesterday_day = '30' %}
- {%- set yesterday_month = '09' %}
- {%- elif yesterday_month == '11' %}
- {%- set yesterday_day = '31' %}
- {%- set yesterday_month = '10' %}
- {%- elif yesterday_month == '12' %}
- {%- set yesterday_day = '30' %}
- {%- set yesterday_month = '11' %}
- {%- endif %}
- {%- elif yesterday_day == '02' %}
- {%- set yesterday_day = '01' %}
- {%- elif yesterday_day == '03' %}
- {%- set yesterday_day = '02' %}
- {%- elif yesterday_day == '04' %}
- {%- set yesterday_day = '03' %}
- {%- elif yesterday_day == '05' %}
- {%- set yesterday_day = '04' %}
- {%- elif yesterday_day == '06' %}
- {%- set yesterday_day = '05' %}
- {%- elif yesterday_day == '07' %}
- {%- set yesterday_day = '06' %}
- {%- elif yesterday_day == '08' %}
- {%- set yesterday_day = '07' %}
- {%- elif yesterday_day == '09' %}
- {%- set yesterday_day = '08' %}
- {%- elif yesterday_day == '10' %}
- {%- set yesterday_day = '09' %}
- {%- elif yesterday_day == '11' %}
- {%- set yesterday_day = '10' %}
- {%- elif yesterday_day == '12' %}
- {%- set yesterday_day = '11' %}
- {%- elif yesterday_day == '13' %}
- {%- set yesterday_day = '12' %}
- {%- elif yesterday_day == '14' %}
- {%- set yesterday_day = '13' %}
- {%- elif yesterday_day == '15' %}
- {%- set yesterday_day = '14' %}
- {%- elif yesterday_day == '16' %}
- {%- set yesterday_day = '15' %}
- {%- elif yesterday_day == '17' %}
- {%- set yesterday_day = '16' %}
- {%- elif yesterday_day == '18' %}
- {%- set yesterday_day = '17' %}
- {%- elif yesterday_day == '19' %}
- {%- set yesterday_day = '18' %}
- {%- elif yesterday_day == '20' %}
- {%- set yesterday_day = '19' %}
- {%- elif yesterday_day == '21' %}
- {%- set yesterday_day = '20' %}
- {%- elif yesterday_day == '22' %}
- {%- set yesterday_day = '21' %}
- {%- elif yesterday_day == '23' %}
- {%- set yesterday_day = '22' %}
- {%- elif yesterday_day == '24' %}
- {%- set yesterday_day = '23' %}
- {%- elif yesterday_day == '25' %}
- {%- set yesterday_day = '24' %}
- {%- elif yesterday_day == '26' %}
- {%- set yesterday_day = '25' %}
- {%- elif yesterday_day == '27' %}
- {%- set yesterday_day = '26' %}
- {%- elif yesterday_day == '28' %}
- {%- set yesterday_day = '27' %}
- {%- elif yesterday_day == '29' %}
- {%- set yesterday_day = '28' %}
- {%- elif yesterday_day == '30' %}
- {%- set yesterday_day = '29' %}
- {%- elif yesterday_day == '31' %}
- {%- set yesterday_day = '30' %}
- {%- endif %}
- {#- Edits made by Unsloth #}
- {%- set yesterday_date = yesterday_year + '-' + yesterday_month + '-' + yesterday_day %}
- {#- ULTRA THINK: hard default reasoning effort to high unless caller overrides #}
- {%- if reasoning_effort is not defined or reasoning_effort is none or reasoning_effort == '' %}
- {%- set reasoning_effort = 'high' %}
- {%- endif %}
- {#- ULTRA THINK: configurable target length (purely instructive) #}
- {%- if ultra_think_target_tokens is not defined or ultra_think_target_tokens is none or ultra_think_target_tokens == '' %}
- {%- set ultra_think_target_tokens = 1400 %}
- {%- endif %}
- {#- ULTRA THINK guidance injected into system prompt (strong priming) #}
- {%- set think_guidelines =
- "## ULTRA THINK MODE (MANDATORY)\n"
- + "Reasoning effort: " + reasoning_effort + ".\n\n"
- + "For EVERY non-tool answer you produce:\n"
- + "1) You MUST start your message with: <think>\n"
- + "2) Inside <think> you MUST write a LONG, explicit reasoning trace. Target: at least ~" + (ultra_think_target_tokens|string) + " tokens of thinking.\n"
- + "3) Your <think> MUST include these sections, in order, with headings exactly as written:\n"
- + " - \"Restate the task\"\n"
- + " - \"Assumptions & unknowns\"\n"
- + " - \"Plan\"\n"
- + " - \"Approach A\"\n"
- + " - \"Approach B\"\n"
- + " - \"Approach C\"\n"
- + " - \"Choose & justify\"\n"
- + " - \"Step-by-step derivation\"\n"
- + " - \"Self-check & edge cases\"\n"
- + " - \"Final verification\"\n"
- + "4) You MUST do at least one correction/verification pass where you try to find mistakes and fix them.\n"
- + "5) ONLY after that, you MUST close with </think> and then provide the final user-facing answer.\n\n"
- + "## TOOL CALLING (CRITICAL)\n"
- + "If you decide to call ANY tool(s), you MUST output NO normal text at all in that assistant message:\n"
- + "- Do NOT output <think>.\n"
- + "- Do NOT output explanations.\n"
- + "- Start immediately with the tool-call format required by the runtime.\n"
- + "After tool results are received, you then follow ULTRA THINK MODE for the final answer.\n\n"
- + "## STYLE\n"
- + "- Be meticulous, exhaustive, and explicit in <think>.\n"
- + "- In the final answer (after </think>), be concise and actionable unless the user asks for depth.\n"
- %}
- {#- Default system message if no system prompt is passed. #}
- {%- set default_system_message =
- "You are Devstral-Medium-2-124B-Instruct-2512, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.\n"
- + "You power an AI assistant called Le Chat.\n"
- + "Your knowledge base was last updated on 2023-10-01.\n"
- + "The current date is " + today_date + ".\n\n"
- + think_guidelines + "\n\n"
- + "When you\'re not sure about some information or when the user\'s request requires up-to-date or specific data, you must use the available tools to fetch the information. Do not hesitate to use tools whenever they can provide a more accurate or complete response. If no relevant tools are available, then clearly state that you don\'t have the information and avoid making up anything.\n"
- + "If the user\'s question is not clear, ambiguous, or does not provide enough context for you to accurately answer the question, you do not try to answer it right away and you rather ask the user to clarify their request (e.g. \"What are some good restaurants around me?\" => \"Where are you?\" or \"When is the next flight to Tokyo\" => \"Where do you travel from?\").\n"
- + "You are always very attentive to dates, in particular you try to resolve dates (e.g. \"yesterday\" is " + yesterday_date + ") and when asked about information at specific dates, you discard information that is at another date.\n"
- + "You follow these instructions in all languages, and always respond to the user in the language they use or request.\n"
- + "Next sections describe the capabilities that you have.\n\n"
- + "# WEB BROWSING INSTRUCTIONS\n\n"
- + "You cannot perform any web search or access internet to open URLs, links etc. If it seems like the user is expecting you to do so, you clarify the situation and ask the user to copy paste the text directly in the chat.\n\n"
- + "# MULTI-MODAL INSTRUCTIONS\n\n"
- + "You have the ability to read images, but you cannot generate images. You also cannot transcribe audio files or videos.\n"
- + "You cannot read nor transcribe audio files or videos.\n\n"
- + "# TOOL CALLING INSTRUCTIONS\n\n"
- + "You may have access to tools that you can use to fetch information or perform actions. You must use these tools in the following situations:\n\n"
- + "1. When the request requires up-to-date information.\n"
- + "2. When the request requires specific data that you do not have in your knowledge base.\n"
- + "3. When the request involves actions that you cannot perform without tools.\n\n"
- + "Always prioritize using tools to provide the most accurate and helpful response. If tools are not available, inform the user that you cannot perform the requested action at the moment."
- %}
- {#- Begin of sequence token. #}
- {{- bos_token }}
- {#- Handle system prompt if it exists. #}
- {#- System prompt supports text content or text chunks. #}
- {%- if messages[0]['role'] == 'system' %}
- {{- '[SYSTEM_PROMPT]' -}}
- {%- if messages[0]['content'] is string %}
- {{- messages[0]['content'] -}}
- {%- else %}
- {%- for block in messages[0]['content'] %}
- {%- if block['type'] == 'text' %}
- {{- block['text'] }}
- {%- else %}
- {{- raise_exception('Only text chunks are supported in system message contents.') }}
- {%- endif %}
- {%- endfor %}
- {%- endif %}
- {#- ULTRA THINK: inject guidance even when user supplies the system prompt #}
- {{- '\n\n' + think_guidelines + '\n' -}}
- {{- '[/SYSTEM_PROMPT]' -}}
- {%- set loop_messages = messages[1:] %}
- {%- else %}
- {%- set loop_messages = messages %}
- {%- if default_system_message != '' %}
- {{- '[SYSTEM_PROMPT]' + default_system_message + '[/SYSTEM_PROMPT]' }}
- {%- endif %}
- {%- endif %}
- {#- Tools definition #}
- {%- set tools_definition = '' %}
- {%- set has_tools = false %}
- {%- if tools is defined and tools is not none and tools|length > 0 %}
- {%- set has_tools = true %}
- {%- set tools_definition = '[AVAILABLE_TOOLS]' + (tools| tojson) + '[/AVAILABLE_TOOLS]' %}
- {{- tools_definition }}
- {%- endif %}
- {#- Checks for alternating user/assistant messages. #}
- {%- set ns = namespace(index=0) %}
- {%- for message in loop_messages %}
- {%- if message.role == 'user' or (message.role == 'assistant' and (message.tool_calls is not defined or message.tool_calls is none or message.tool_calls | length == 0)) %}
- {%- if (message['role'] == 'user') != (ns.index % 2 == 0) %}
- {{- raise_exception('After the optional system message, conversation roles must alternate user and assistant roles except for tool calls and results.') }}
- {%- endif %}
- {%- set ns.index = ns.index + 1 %}
- {%- endif %}
- {%- endfor %}
- {#- Handle conversation messages. #}
- {%- for message in loop_messages %}
- {#- User messages supports text content or text and image chunks. #}
- {%- if message['role'] == 'user' %}
- {%- if message['content'] is string %}
- {{- '[INST]' + message['content'] + '[/INST]' }}
- {%- elif message['content'] | length > 0 %}
- {{- '[INST]' }}
- {%- if message['content'] | length == 2 %}
- {%- set blocks = message['content'] | sort(attribute='type') %}
- {%- else %}
- {%- set blocks = message['content'] %}
- {%- endif %}
- {%- for block in blocks %}
- {%- if block['type'] == 'text' %}
- {{- block['text'] }}
- {%- elif block['type'] in ['image', 'image_url'] %}
- {{- '[IMG]' }}
- {%- else %}
- {{- raise_exception('Only text, image and image_url chunks are supported in user message content.') }}
- {%- endif %}
- {%- endfor %}
- {{- '[/INST]' }}
- {%- else %}
- {{- raise_exception('User message must have a string or a list of chunks in content') }}
- {%- endif %}
- {#- Assistant messages supports text content or text chunks. #}
- {%- elif message['role'] == 'assistant' %}
- {%- if (message['content'] is none or message['content'] == '' or message['content']|length == 0) and (message['tool_calls'] is not defined or message['tool_calls'] is none or message['tool_calls']|length == 0) %}
- {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
- {%- endif %}
- {#- IMPORTANT: do NOT inject <think> here. Tool-call messages must start with [TOOL_CALLS]. #}
- {%- if message['content'] is string %}
- {{- message['content'] }}
- {%- elif message['content'] is iterable and message['content'] | length > 0 %}
- {%- for block in message['content'] %}
- {%- if block['type'] == 'text' %}
- {{- block['text'] }}
- {%- else %}
- {{- raise_exception('Only text chunks are supported in assistant message contents.') }}
- {%- endif %}
- {%- endfor %}
- {%- endif %}
- {%- if message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls']|length > 0 %}
- {%- for tool in message['tool_calls'] %}
- {%- set arguments = tool['function']['arguments'] %}
- {%- if arguments is not string %}
- {%- set arguments = arguments|tojson|safe %}
- {%- elif arguments == '' %}
- {%- set arguments = '{}' %}
- {%- endif %}
- {{- '[TOOL_CALLS]' + tool['function']['name'] + '[ARGS]' + arguments }}
- {%- endfor %}
- {%- endif %}
- {#- End of sequence token for each assistant messages. #}
- {{- eos_token }}
- {#- Tool messages only supports text content. #}
- {%- elif message['role'] == 'tool' %}
- {{- '[TOOL_RESULTS]' + message['content']|string + '[/TOOL_RESULTS]' }}
- {#- Raise exception for unsupported roles. #}
- {%- else %}
- {{- raise_exception('Only user, assistant and tool roles are supported, got ' + message['role'] + '.') }}
- {%- endif %}
- {%- endfor %}
- {#- Copyright 2025-present Unsloth. Apache 2.0 License. #}
Advertisement
Add Comment
Please, Sign In to add comment