Skip to content

Commit 901e20b

Browse files
jinja : Add Mistral-Small-3.2-24B-Instruct-2506.jinja (#14349)
This will allow the use of tools on the llama-server
1 parent 0142961 commit 901e20b

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{%- set today = strftime_now("%Y-%m-%d") %}
2+
{%- set default_system_message = "You are Mistral Small 3, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.\nYour knowledge base was last updated on 2023-10-01. The current date is " + today + ".\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.
3+
4+
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?\").
5+
You are always very attentive to dates, and when asked about information at specific dates, you discard information that is at another date.
6+
You follow these instructions in all languages, and always respond to the user in the language they use or request.
7+
Next sections describe the capabilities that you have.
8+
9+
# WEB BROWSING INSTRUCTIONS
10+
11+
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.
12+
13+
# MULTI-MODAL INSTRUCTIONS
14+
15+
You have the ability to read images, but you cannot generate images. You also cannot transcribe audio files or videos.
16+
You cannot read nor transcribe audio files or videos.
17+
18+
# TOOL CALLING INSTRUCTIONS
19+
20+
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:
21+
22+
1. When the request requires up-to-date information.
23+
2. When the request requires specific data that you do not have in your knowledge base.
24+
3. When the request involves actions that you cannot perform without tools.
25+
26+
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." %}
27+
28+
{{- bos_token }}
29+
30+
{%- set system_prompt = default_system_message %}
31+
{%- set loop_messages = messages %}
32+
33+
{%- if not tools is defined %}
34+
{%- set tools = none %}
35+
{%- endif %}
36+
37+
{%- if messages|length > 0 and messages[0]['role'] == 'system' %}
38+
{%- if messages[0]['content'] is string %}
39+
{%- set system_prompt = messages[0]['content'] %}
40+
{%- else %}
41+
{%- set system_prompt = messages[0]['content'][0]['text'] %}
42+
{%- endif %}
43+
{%- set loop_messages = messages[1:] %}
44+
{%- endif %}
45+
46+
{%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
47+
48+
{%- set ns = namespace(index=0) %}
49+
{%- for message in loop_messages %}
50+
{%- if not (message.role == "tool" or (message.get('tool_calls'))) %}
51+
{%- if (message["role"] == "user") != (ns.index % 2 == 0) %}
52+
{{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }}
53+
{%- endif %}
54+
{%- set ns.index = ns.index + 1 %}
55+
{%- endif %}
56+
{%- endfor %}
57+
58+
{{- '[SYSTEM_PROMPT]' + system_prompt + '[/SYSTEM_PROMPT]' }}
59+
60+
{%- for message in loop_messages %}
61+
{%- if message['role'] == 'system' %}
62+
{%- if message['content'] is string %}
63+
{{- '[SYSTEM_PROMPT]' + message['content'] + '[/SYSTEM_PROMPT]' }}
64+
{%- else %}
65+
{{- '[SYSTEM_PROMPT]' + message['content'][0]['text'] + '[/SYSTEM_PROMPT]' }}
66+
{%- endif %}
67+
{%- elif message['role'] == 'user' %}
68+
{%- if tools is not none and (message == user_messages[-1]) %}
69+
{{- '[AVAILABLE_TOOLS]' + tools|tojson + '[/AVAILABLE_TOOLS]' }}
70+
{%- endif %}
71+
{{- '[INST]' }}
72+
{%- if message['content'] is string %}
73+
{{- message['content'] }}
74+
{%- else %}
75+
{%- for block in message['content'] %}
76+
{%- if block['type'] == 'text' %}
77+
{{- block['text'] }}
78+
{%- elif block['type'] in ['image', 'image_url'] %}
79+
{{- '[IMG]' }}
80+
{%- else %}
81+
{{- raise_exception('Only text and image blocks are supported in message content!') }}
82+
{%- endif %}
83+
{%- endfor %}
84+
{%- endif %}
85+
{{- '[/INST]' }}
86+
{%- elif message['role'] == 'assistant' %}
87+
{%- if message.get('tool_calls') %}
88+
{%- for tool_call in message.tool_calls %}
89+
{{- '[TOOL_CALLS]' + tool_call.function.name }}
90+
{%- if not tool_call.id is defined or tool_call.id is not string or tool_call.id|length != 9 %}
91+
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
92+
{%- endif %}
93+
{{- '[CALL_ID]' + tool_call.id }}
94+
{{- '[ARGS]' + tool_call['function']['arguments']|tojson }}
95+
{%- endfor %}
96+
{{- eos_token }}
97+
{%- elif message['content'] is string %}
98+
{{- message['content'] + eos_token }}
99+
{%- else %}
100+
{%- for block in message['content'] %}
101+
{%- if block['type'] == 'text' %}
102+
{{- block['text'] }}
103+
{%- elif block['type'] in ['image', 'image_url'] %}
104+
{{- '[IMG]' }}
105+
{%- else %}
106+
{{- raise_exception('Only text and image blocks are supported in assistant content!') }}
107+
{%- endif %}
108+
{%- endfor %}
109+
{{- eos_token }}
110+
{%- endif %}
111+
{%- elif message['role'] == 'tool_results' or message['role'] == 'tool' %}
112+
{%- if message.content is defined and message.content.content is defined %}
113+
{%- set content = message.content.content %}
114+
{%- else %}
115+
{%- set content = message.content %}
116+
{%- endif %}
117+
{%- if not message.tool_call_id is defined or message.tool_call_id is not string or message['tool_call_id']|length != 9 %}
118+
{{- raise_exception("Tool call IDs should be alphanumeric strings with length 9!") }}
119+
{%- endif %}
120+
{{- '[TOOL_RESULTS]' + message.tool_call_id + '[TOOL_CONTENT]' + content|string + '[/TOOL_RESULTS]' }}
121+
{%- else %}
122+
{{- raise_exception('Only system, user, assistant, and tool roles are supported!') }}
123+
{%- endif %}
124+
{%- endfor %}

0 commit comments

Comments
 (0)