Models
GitHub
Discord
Docs
Cloud
Sign in
Download
Models
Download
GitHub
Discord
Docs
Cloud
Sign in
gabegoodhart
/
minimax-m2
:latest
51
Downloads
Updated
5 days ago
Cancel
tools
thinking
230b
minimax-m2:latest
...
/
template
d48f8a57e91e · 6.6kB
{{- /*
Ollama-compatible Go template for MiniMax
Translated from Jinja2 template
*/ -}}
{{- /* Special token variables */ -}}
{{- $toolcall_begin := "<minimax:tool_call>" -}}
{{- $toolcall_end := "</minimax:tool_call>" -}}
{{- $thought_start_tag := "<think>" -}}
{{- $thought_end_tag := "</think>" -}}
{{- /*
Output parsing heuristic for Ollama tag detection
https://github.com/ollama/ollama/blob/main/thinking/template.go
https://github.com/ollama/ollama/blob/main/tools/template.go
*/ -}}
{{- if false }}
{{- range .Messages }}
{{- if .Thinking }}<think>{{ .Thinking }}</think>{{- end }}
{{- end }}
{{- if .ToolCalls }}<minimax:tool_call>{{- end }}
{{- end }}
{{- /* Parse system message and find last user index */ -}}
{{- $system_message := "" -}}
{{- $last_user_index := -1 -}}
{{- range $index, $_ := .Messages -}}
{{- if and (eq .Role "system") (eq $index 0) -}}
{{- $system_message = .Content -}}
{{- else if eq .Role "user" -}}
{{- $last_user_index = $index -}}
{{- end -}}
{{- end -}}
{{- /* Render system message */ -}}
]~!b[]~b]system
{{- if ne $system_message "" }}
{{ $system_message }}
{{- else }}
You are a helpful assistant.
{{- end }}
{{- /* Render tools if available */ -}}
{{- if .Tools }}
# Tools
You may call one or more tools to assist with the user query.
Here are the tools available in JSONSchema format:
<tools>
{{- range .Tools }}
<tool>{{ json .Function }}</tool>
{{ end -}}
</tools>
When making tool calls, use XML format to invoke tools and pass parameters:
{{ $toolcall_begin }}
<invoke name="tool-name-1">
<parameter name="param-key-1">param-value-1</parameter>
<parameter name="param-key-2">param-value-2</parameter>
...
</invoke>
{{ $toolcall_end }}
{{- end }}
[e~[
{{- /* Render messages */ -}}
{{- $prev_role := "" -}}
{{- range $message_index, $_ := .Messages -}}
{{- $next_message_index := len (printf "a%*s" $message_index "") -}}
{{- $skip_system := and (eq .Role "system") (eq $message_index 0) -}}
{{- if and (eq .Role "assistant") (not $skip_system) -}}
]~b]ai
{{- /* Parse thoughts from .Thinking or .Content */ -}}
{{- $content := .Content -}}
{{- $thought := "" -}}
{{- if .Thinking -}}
{{- $thought = .Thinking -}}
{{- else -}}
{{- /* Character-by-character parser for <think>...</think> */ -}}
{{- $thought_start := 0 -}}
{{- $thought_end := 0 -}}
{{- $prefix_end := 0 -}}
{{- $suffix_start := 0 -}}
{{- $tag_start := 0 -}}
{{- $tag_len := 1 -}}
{{- $prefix := "" -}}
{{- $suffix := "" -}}
{{- range (len .Content) }}{{ $idx := . -}}
{{- $candidate := slice $content $tag_start $idx -}}
{{- $tag := $thought_start_tag -}}
{{- if ne $thought_start 0 -}}
{{- $tag = $thought_end_tag -}}
{{- end -}}
{{- $suffix_start_plus_one := len (printf "a%*s" $suffix_start "") -}}
{{- if and (ne $suffix_start 0) (lt $suffix_start_plus_one (len $content)) (eq (slice $content
$suffix_start $suffix_start_plus_one) "\n") -}}
{{- $suffix_start = $suffix_start_plus_one -}}
{{- end -}}
{{- $tag_prefix := "" -}}
{{- if le $tag_len (len $tag) -}}
{{- $tag_prefix = slice $tag 0 $tag_len -}}
{{- end -}}
{{- if eq $tag_prefix $candidate -}}
{{- if eq $tag_prefix $tag -}}
{{- if eq $thought_start 0 -}}
{{- $prefix_end = $tag_start -}}
{{- $thought_start = $idx -}}
{{- else -}}
{{- $thought_end = $tag_start -}}
{{- $suffix_start = $idx -}}
{{- end -}}
{{- $tag_len = 0 -}}
{{- else -}}
{{- $tag_len = len (printf "a%*s" $tag_len "") -}}
{{- end -}}
{{- else -}}
{{- $tag_start = $idx -}}
{{- $tag_len = 1 -}}
{{- end -}}
{{- end -}}
{{- if gt $thought_end $thought_start -}}
{{- $thought = slice .Content $thought_start $thought_end -}}
{{- if gt $prefix_end 0 -}}
{{- $prefix = slice .Content 0 $prefix_end -}}
{{- end -}}
{{- if and (gt $suffix_start 0) (lt $suffix_start (len .Content)) -}}
{{- $suffix = slice .Content $suffix_start -}}
{{- end -}}
{{- else -}}
{{- $prefix = .Content -}}
{{- end -}}
{{- $content = print $prefix $suffix -}}
{{- end -}}
{{- /* Only render thinking if after last user message */ -}}
{{- if and (gt $message_index $last_user_index) (ne $thought "") }}
<think>
{{ $thought }}
</think>
{{- end -}}
{{- if ne $content "" }}
{{ $content }}
{{- end -}}
{{- /* Render tool calls */ -}}
{{- if .ToolCalls }}
{{ $toolcall_begin }}
{{- range .ToolCalls }}
<invoke name="{{ .Function.Name }}">
{{- range $k, $v := .Function.Arguments }}
<parameter name="{{ $k }}">{{ $v }}</parameter>
{{- end }}
</invoke>
{{- end }}
{{ $toolcall_end }}
{{- end -}}
[e~[
{{- $prev_role = "assistant" -}}
{{- else if and (eq .Role "tool") (not $skip_system) -}}
{{- if ne $prev_role "tool" -}}
]~b]tool
{{- end -}}
<response>{{ .Content }}</response>
{{- /* Check if next message is not tool to close block */ -}}
{{- if ne $next_message_index (len $.Messages) -}}
{{- $next_element := index $.Messages $next_message_index -}}
{{- if ne $next_element.Role "tool" -}}
[e~[
{{- $prev_role = "tool_closed" -}}
{{- else -}}
{{- $prev_role = "tool" -}}
{{- end -}}
{{- else -}}
[e~[
{{- $prev_role = "tool_closed" -}}
{{- end -}}
{{- else if and (eq .Role "user") (not $skip_system) -}}
]~b]user
{{ .Content }}[e~[
{{- $prev_role = "user" -}}
{{- end -}}
{{- /* Generation prompt at end if not assistant */ -}}
{{- if and (eq $next_message_index (len $.Messages)) (ne .Role "assistant") -}}
]~b]ai
<think>
{{- end -}}
{{- end -}}