28 1 week ago

A Quantized, Fine-Tuned Model for Enhanced Tool Calling, Code Generation, and Reasoning

tools thinking
{{- define "value" -}}
{{- if eq (printf "%T" .) "string" -}}
{{ . }}
{{- else if eq (printf "%T" .) "bool" -}}
{{ if . }}True{{ else }}False{{ end }}
{{- else if eq (printf "%T" .) "<nil>" -}}
None
{{- else -}}
{{ json . }}
{{- end -}}
{{- end -}}
{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end -}}
<|im_start|>system
{{ .System }}{{ if .Tools }}{{ if .System }}
{{ end }}# Tools
You have access to the following functions:
<tools>
{{- range .Tools }}
<function>
<name>{{ .Function.Name }}</name>
{{- if .Function.Description }}
<description>{{ .Function.Description }}</description>
{{- end }}
<parameters>
{{- range $name, $field := .Function.Parameters.Properties }}
<parameter>
<name>{{ $name }}</name>
{{- if $field.Type }}
<type>{{ if eq (len $field.Type) 1 }}{{ index $field.Type 0 }}{{ else }}{{ json $field.Type }}{{ end }}</type>
{{- end }}
{{- if $field.Description }}
<description>{{ $field.Description }}</description>
{{- end }}
{{- if $field.Enum }}
<enum>{{ json $field.Enum }}</enum>
{{- end }}
{{- if $field.AnyOf }}
<anyOf>{{ json $field.AnyOf }}</anyOf>
{{- end }}
{{- if $field.Items }}
<items>{{ json $field.Items }}</items>
{{- end }}
{{- if $field.Properties }}
<properties>{{ json $field.Properties }}</properties>
{{- end }}
{{- if $field.Required }}
<required>{{ json $field.Required }}</required>
{{- end }}
{{- range $key, $value := $field.Extra }}
<{{ $key }}>{{ template "value" $value }}</{{ $key }}>
{{- end }}
</parameter>
{{- end }}
{{- if .Function.Parameters.Defs }}
<$defs>{{ json .Function.Parameters.Defs }}</$defs>
{{- end }}
{{- if .Function.Parameters.Items }}
<items>{{ json .Function.Parameters.Items }}</items>
{{- end }}
{{- if .Function.Parameters.Required }}
<required>{{ json .Function.Parameters.Required }}</required>
{{- end }}
</parameters>
</function>
{{- end }}
</tools>
If you choose to call a function ONLY reply in the following format with NO suffix:
<tool_call>
<function=example_function_name>
<parameter=example_parameter_1>
value_1
</parameter>
<parameter=example_parameter_2>
This is the value for the second parameter
that can span
multiple lines
</parameter>
</function>
</tool_call>
<IMPORTANT>
Reminder:
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
- Required parameters MUST be specified
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
</IMPORTANT>
{{- end }}<|im_end|>
{{ $previousRole := "" -}}
{{- range $i, $_ := .Messages -}}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if and (eq $previousRole "tool") (ne .Role "tool") -}}
<|im_end|>
{{ end -}}
{{- if eq .Role "user" -}}
<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" -}}
<|im_start|>assistant
{{ if and .Thinking (gt $i $lastUserIdx) -}}
<think>
{{ .Thinking }}</think>
{{- else if or .Thinking (and (ne (printf "%.7s" .Content) "<think>") (ne (printf "%.8s" .Content) "</think>")) -}}
<think></think>
{{- end -}}
{{ .Content }}
{{- if .ToolCalls }}
{{ range .ToolCalls -}}
<tool_call>
<function={{ .Function.Name }}>
{{- range $name, $value := .Function.Arguments }}
<parameter={{ $name }}>
{{ template "value" $value }}
</parameter>
{{- end }}
</function>
</tool_call>
{{ end -}}
{{- end -}}
{{ if not $last }}<|im_end|>
{{ end -}}
{{- else if eq .Role "tool" -}}
{{ if ne $previousRole "tool" -}}
<|im_start|>user
{{ end -}}
<tool_response>
{{ .Content }}
</tool_response>
{{ if $last -}}
<|im_end|>
{{ end -}}
{{- end -}}
{{- $previousRole = .Role -}}
{{- if and (ne .Role "assistant") $last -}}
<|im_start|>assistant
{{ if or (not $.IsThinkSet) $.Think -}}
<think>
{{ else -}}
<think></think>
{{- end -}}
{{- end -}}
{{- end }}