File size: 13,349 Bytes
b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c 87bd2e6 b4fbd1c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
{%- 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' %}
{%- else %}
{{- raise_exception('Unsloth custom template does not support years > 2028') }}
{%- 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' %}
{%- else %}
{{- raise_exception('Unsloth custom template does not support years > 2028') }}
{%- 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 %}
{%- set default_system_message = "You are Mistral-Small-3.2-24B-Instruct-2506, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.\nYou power an AI assistant called Le Chat.\nYour knowledge base was last updated on 2023-10-01.\nThe current date is " + today_date + ".\n\nWhen 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.\nIf 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?\").\nYou 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.\nYou follow these instructions in all languages, and always respond to the user in the language they use or request.\nNext sections describe the capabilities that you have.\n\n# WEB BROWSING INSTRUCTIONS\n\nYou 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\nYou have the ability to read images, but you cannot generate images. You also cannot transcribe audio files or videos.\nYou cannot read nor transcribe audio files or videos.\n\nTOOL CALLING INSTRUCTIONS\n\nYou 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\n1. When the request requires up-to-date information.\n2. When the request requires specific data that you do not have in your knowledge base.\n3. When the request involves actions that you cannot perform without tools.\n\nAlways 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." %}
{{- bos_token }}
{%- if messages[0]['role'] == 'system' %}
{%- if messages[0]['content'] is string %}
{%- set system_message = messages[0]['content'] %}
{%- else %}
{%- set system_message = messages[0]['content'][0]['text'] %}
{%- endif %}
{%- set loop_messages = messages[1:] %}
{%- else %}
{%- set system_message = default_system_message %}
{%- set loop_messages = messages %}
{%- endif %}
{{- '[SYSTEM_PROMPT]' + system_message + '[/SYSTEM_PROMPT]' }}
{#- Tool description appended ONLY to last user message. Edits made by Unsloth #}
{#- Tool description appended also if last message is tool. Edits made by Unsloth #}
{%- set tools_description = "" %}
{%- set has_tools = false %}
{#- Cannot use set append_tools_index = loop.index0 since temporary variable - must use namespace #}
{%- set ns = namespace(append_tools_index=0, append_tools=false) %}
{%- if tools is defined and tools is not none and tools|length > 0 %}
{%- set has_tools = true %}
{%- set tools_description = "[AVAILABLE_TOOLS]" + (tools | tojson) + "[/AVAILABLE_TOOLS]" %}
{#- If User,Assistant,Tool,Tool we also need to append tools_description to last assistant WITHOUT tool_calls defined. Edits made by Unsloth #}
{%- if (loop_messages|last)['role'] == 'tool' %}
{#- Find last assistant WITHOUT tool_calls defined #}
{%- set ns.append_tools = true %}
{%- for message in loop_messages %}
{%- if message['role'] == 'assistant' %}
{#- Cannot use set append_tools_index = loop.index0 since temporary variable - must use namespace #}
{%- if message['tool_calls'] is not defined or message['tool_calls'] is none %}
{%- set ns.append_tools_index = loop.index0 %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endif %}
{%- for message in loop_messages %}
{%- if message['role'] == 'user' %}
{%- if has_tools and loop.last %}
{{- tools_description }}
{%- endif %}
{#- If directly called tools in first turn, prepend to user #}
{%- if ns.append_tools and ns.append_tools_index == 0 %}
{{- tools_description }}
{%- endif %}
{%- if message['content'] is string %}
{{- '[INST]' + message['content'] + '[/INST]' }}
{%- else %}
{{- '[INST]' }}
{%- for block in message['content'] %}
{%- if block['type'] == 'text' %}
{#- Original did not have content which is weird. Added by Un-sloth. #}
{%- if block['text'] is defined %}
{{- block['text'] }}
{%- else %}
{{- block['content'] }}
{%- endif %}
{%- elif block['type'] in ['image', 'image_url'] %}
{{- '[IMG]' }}
{%- else %}
{{- raise_exception('Only text and image blocks are supported in message content!') }}
{%- endif %}
{%- endfor %}
{{- '[/INST]' }}
{%- endif %}
{%- elif message['role'] == 'system' %}
{%- if message['content'] is string %}
{{- '[SYSTEM_PROMPT]' + message['content'] + '[/SYSTEM_PROMPT]' }}
{%- else %}
{{- '[SYSTEM_PROMPT]' + message['content'][0]['text'] + '[/SYSTEM_PROMPT]' }}
{%- endif %}
{%- elif message['role'] == 'assistant' %}
{%- if message['content'] is string %}
{{- message['content'] }}
{%- else %}
{{- message['content'][0]['text'] }}
{%- endif %}
{#- If User,Assistant,Tool,Tool we also need to append tools_description. Edits made by Unsloth #}
{%- if has_tools and (loop.index0 == ns.append_tools_index) %}
{{- eos_token }}
{{- tools_description }}
{%- endif %}
{%- if message['tool_calls'] is defined and message['tool_calls'] is not none %}
{%- for tool in message['tool_calls'] %}
{%- if tool['id'] is not defined %}
{{- raise_exception('Tool ID must be provided!') }}
{%- endif %}
{%- set tool_call_id = tool['id'] %}
{%- if tool_call_id is not string or tool_call_id|length < 9 %}
{{- raise_exception("Tool call IDs should be alphanumeric strings with length >= 9!") }}
{%- endif %}
{%- set arguments = tool['function']['arguments'] %}
{%- if arguments is not string %}
{%- set arguments = arguments|tojson %}
{%- endif %}
{#- Must list tool calls AFTER assistant. Edits made by Un-sloth #}
{{- "[TOOL_CALLS]" + tool['function']['name'] + "[CALL_ID]" + tool_call_id + "[ARGS]" + arguments }}
{%- endfor %}
{%- endif %}
{#- Must not add EOS if added tools_description. Unsloth edits. #}
{%- if (loop.index0 != ns.append_tools_index) %}
{{- eos_token }}
{%- endif %}
{%- elif message['role'] == 'tool' %}
{%- if message['tool_call_id'] is not defined %}
{{- raise_exception('tool_call_id must be provided!') }}
{%- endif %}
{%- set tool_call_id = message['tool_call_id'] %}
{%- if tool_call_id is not string or tool_call_id|length < 9 %}
{{- raise_exception("Tool call IDs should be alphanumeric strings with length >= 9!") }}
{%- endif %}
{{- "[TOOL_RESULTS]" + tool_call_id + "[TOOL_CONTENT]" + message['content'] + "[/TOOL_RESULTS]" }}
{%- else %}
{{- raise_exception('Only user, systemm assistant and tool roles are supported in the custom template made by Unsloth!') }}
{%- endif %}
{%- endfor %} |