32 6 days ago

tools thinking 2b
8a6d93580356 ยท 4.9kB
<|startoftext|>
{{- /* LFM3 chat format (as Liquid's template and Ollama's lfm3 renderer) with reasoning effort: think false = off, low,
true / medium = the model's own length, high, max = no limit (the whole 128K window, 3.1 GB in Ollama). The effort goes in as the
system prompt's first line (effort.py); checked against Liquid's HF template with tplcheck.py. */ -}}
{{- define "str" }}{{ printf "%q" . }}{{ end }}
{{- define "val" }}{{ if eq (printf "%T" .) "string" }}{{ printf "%q" . }}{{ else }}{{ json . }}{{ end }}{{ end }}
{{- define "type" }}{{ if eq (len .) 1 }}{{ template "str" (index . 0) }}{{ else }}[{{ range $n, $x := . }}{{ if $n }}, {{ end }}{{ template "str" $x }}{{ end }}]{{ end }}{{ end }}
{{- define "prop" }}{{ "{" }}{{ $f := true }}
{{- if .Type }}"type": {{ template "type" .Type }}{{ $f = false }}{{ end }}
{{- if .Description }}{{ if not $f }}, {{ end }}"description": {{ template "str" .Description }}{{ $f = false }}{{ end }}
{{- if .Enum }}{{ if not $f }}, {{ end }}"enum": [{{ range $n, $x := .Enum }}{{ if $n }}, {{ end }}{{ template "val" $x }}{{ end }}]{{ $f = false }}{{ end }}
{{- if .Items }}{{ if not $f }}, {{ end }}"items": {{ json .Items }}{{ $f = false }}{{ end }}
{{- if .Properties }}{{ if not $f }}, {{ end }}"properties": {{ json .Properties }}{{ $f = false }}{{ end }}
{{- if .Required }}{{ if not $f }}, {{ end }}"required": {{ json .Required }}{{ $f = false }}{{ end }}
{{- if .AnyOf }}{{ if not $f }}, {{ end }}"anyOf": {{ json .AnyOf }}{{ end }}{{ "}" }}{{ end }}
{{- define "tool" }}{"name": {{ template "str" .Name }}, "description": {{ template "str" .Description }}, "parameters": {"type": {{ template "str" .Parameters.Type }}
{{- if .Parameters.Defs }}, "$defs": {{ json .Parameters.Defs }}{{ end }}
{{- if .Parameters.Items }}, "items": {{ json .Parameters.Items }}{{ end }}, "properties": {{ "{" }}{{ $f := true }}
{{- range $k, $v := .Parameters.Properties }}{{ if not $f }}, {{ end }}{{ $f = false }}{{ template "str" $k }}: {{ template "prop" $v }}{{ end }}{{ "}" }}
{{- if .Parameters.Required }}, "required": [{{ range $n, $x := .Parameters.Required }}{{ if $n }}, {{ end }}{{ template "str" $x }}{{ end }}]{{ end }}{{ "}}" }}{{ end }}
{{- $think := and .IsThinkSet .Think }}
{{- $effort := "" }}
{{- if $think }}
{{- if or (eq .ThinkLevel "low") (eq .ThinkLevel "minimal") }}{{ $effort = "Reasoning effort: low. Keep your thinking short and go straight to the answer." }}
{{- else if eq .ThinkLevel "high" }}{{ $effort = "Reasoning effort: high. Think the task through carefully and check your work before you answer." }}
{{- else if or (eq .ThinkLevel "max") (eq .ThinkLevel "xhigh") (eq .ThinkLevel "ultra") }}{{ $effort = "Reasoning effort: max. There is no limit on thinking: work through the task completely, test your ideas and check every detail before you answer." }}
{{- end }}
{{- end }}
{{- $system := .System }}
{{- if $effort }}{{ if $system }}{{ $system = printf "%s\n\n%s" $effort $system }}{{ else }}{{ $system = $effort }}{{ end }}{{ end }}
{{- if or $system .Tools }}<|im_start|>system
{{ $system }}{{ if .Tools }}{{ if $system }}
{{ end }}<tools>
{{ range $i, $t := .Tools }}{{ if $i }}
{{ end }}{{ template "tool" $t.Function }}{{ end }}
</tools>{{ end }}<|im_end|>
{{ end }}
{{- $lastUser := -1 }}
{{- range $i, $m := .Messages }}{{ if eq $m.Role "user" }}{{ $lastUser = $i }}{{ end }}{{ end }}
{{- $pending := "" }}
{{- $prefill := false }}
{{- range $i, $m := .Messages }}
{{- $rest := slice $.Messages $i }}
{{- $last := eq (len $rest) 1 }}
{{- if eq $m.Role "system" }}
{{- else if eq $m.Role "tool" }}
{{- $merge := false }}
{{- if and $m.ToolCallID (not $last) }}{{ $next := index $rest 1 }}{{ if and (eq $next.Role "tool") (eq $next.ToolCallID $m.ToolCallID) }}{{ $merge = true }}{{ end }}{{ end }}
{{- if $merge }}{{ if $m.Content }}{{ if $pending }}{{ $pending = printf "%s\n%s" $pending $m.Content }}{{ else }}{{ $pending = $m.Content }}{{ end }}{{ end }}
{{- else }}<|im_start|>tool
<tool_response>
{{ if $pending }}{{ $pending }}{{ if $m.Content }}
{{ end }}{{ end }}{{ $m.Content }}
</tool_response><|im_end|>
{{ $pending = "" }}
{{- end }}
{{- else if eq $m.Role "assistant" }}<|im_start|>assistant
{{ if and (gt $i $lastUser) $m.Thinking }}<think>{{ $m.Thinking }}</think>{{ else }}<think></think>{{ end }}{{ $m.Content }}
{{- range $j, $c := $m.ToolCalls }}{{ if $j }}
{{ end }}<tool_call>
<function={{ $c.Function.Name }}>
{{ range $k, $v := $c.Function.Arguments }}<parameter={{ $k }}>
{{ if eq (printf "%T" $v) "string" }}{{ $v }}{{ else }}{{ json $v }}{{ end }}
</parameter>
{{ end }}</function>
</tool_call>
{{- end }}
{{- if and $last $m.Content }}{{ $prefill = true }}{{ else }}<|im_end|>
{{ end }}
{{- else }}<|im_start|>{{ $m.Role }}
{{ $m.Content }}<|im_end|>
{{ end }}
{{- end }}
{{- if not $prefill }}<|im_start|>assistant
{{ if $think }}<think>{{ else }}<think></think>{{ end }}
{{- end }}