{{- if eq .Role "user" }}{{ $lastUserIndex = $index }}{{ end }}
{{- if eq .Role "system" }}{{ $hasSystemPrompt = true }}{{ end }}
{{- end }}
{{- if not $hasSystemPrompt }}[SYSTEM_PROMPT]You are Ministral, a helpful AI assistant created by Mistral AI.
Your knowledge base was last updated on 2023-10-01.
The current date is {{ currentDate }}.
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.
If no relevant tools are available, then clearly state that you don't have the information and avoid making up anything.
# TOOL CALLING INSTRUCTIONS
{{- if .Tools }}
You have access to the following tools:
[AVAILABLE_TOOLS]{{ .Tools }}[/AVAILABLE_TOOLS]
When you need to call a tool, you MUST use exactly this format:
[TOOL_CALLS]tool_name[ARGS]{"param": "value"}
Rules:
- ALWAYS start with [TOOL_CALLS] before the tool name
- NEVER skip the [TOOL_CALLS] prefix
- One tool call per line in the format: tool_name[ARGS]{json_arguments}
- Do not output any text before [TOOL_CALLS] when calling a tool
{{- else }}
You do not have access to any tools.
{{- end }}[/SYSTEM_PROMPT]
{{- end }}
{{- range $index, $_ := .Messages }}
{{- if eq .Role "system" }}[SYSTEM_PROMPT]{{ .Content }}
{{- if $.Tools }}
# TOOL CALLING INSTRUCTIONS
You have access to the following tools:
[AVAILABLE_TOOLS]{{ $.Tools }}[/AVAILABLE_TOOLS]
When you need to call a tool, you MUST use exactly this format:
[TOOL_CALLS]tool_name[ARGS]{"param": "value"}
Rules:
- ALWAYS start with [TOOL_CALLS] before the tool name
- NEVER skip the [TOOL_CALLS] prefix
- One tool call per line in the format: tool_name[ARGS]{json_arguments}
- Do not output any text before [TOOL_CALLS] when calling a tool
{{- end }}[/SYSTEM_PROMPT]
{{- else if eq .Role "user" }}
{{- if and (eq $lastUserIndex $index) $.Tools }}[AVAILABLE_TOOLS]{{ $.Tools }}[/AVAILABLE_TOOLS]
{{- end }}[INST]{{ .Content }}[/INST]
{{- else if eq .Role "assistant" }}
{{- if .Content }}{{ .Content }}
{{- if and (not .ToolCalls) (not (eq (len (slice $.Messages $index)) 1)) }}</s>
{{- end }}
{{- end }}
{{- if .ToolCalls }}[TOOL_CALLS]
{{- range .ToolCalls }}{{ .Function.Name }}[ARGS]{{ .Function.Arguments }}
{{- end }}</s>
{{- end }}
{{- else if eq .Role "tool" }}[TOOL_RESULTS]{{ .Content }}[/TOOL_RESULTS]