490 11 months ago

tools thinking
8b4a17e7d314 · 2.4kB
{{- /* ───── DictaLM-3.0-24B-Thinking Chat Template (Go text/template) ───── */ -}}
{{- /* Find last user query index */ -}}
{{- $lastQueryIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastQueryIdx = $idx }}{{ end -}}
{{- end -}}
{{- /* System header */ -}}
<|im_start|>system
{{ if .System }}{{ .System }}{{ else }}You are a helpful AI assistant named Dicta-LM 3.0, Trained by Dicta, the Israel Center for Text Analysis. Your role is to provide accurate, helpful, and well-structured responses to user questions and requests.
Provide clear, logical, and precise answers that thoroughly address what the user is asking for. Structure your responses in a way that is easy to understand and follow. You are Dicta-LM 3.0.{{ end -}}
{{- if .Tools }}
## Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end }}<|im_end|>
{{- $prevRoleWasTool := false -}}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if and $prevRoleWasTool (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 ((gt $i $lastQueryIdx)) (or $last .Thinking)) -}}
<think>{{ .Thinking }}</think>{{ end -}}
{{- $hasContent := .Content -}}
{{- if $hasContent }}{{ .Content }}{{- end -}}
{{- if .ToolCalls -}}
{{- range $index, $call := .ToolCalls -}}
{{- if or $hasContent (gt $index 0) }}
{{ end -}}
<tool_call>
{"name": "{{ $call.Function.Name }}", "arguments": {{ $call.Function.Arguments }}}
</tool_call>
{{- end -}}
{{- end -}}<|im_end|>
{{- else if eq .Role "tool" }}
{{ if not $prevRoleWasTool }}<|im_start|>user
{{ end -}}
<tool_response>
{{ .Content }}
</tool_response>
{{- if $last -}}<|im_end|>{{- end -}}
{{- end -}}
{{- if and (ne .Role "assistant") $last }}
<|im_start|>assistant
<think>{{- end -}}
{{- $prevRoleWasTool = eq .Role "tool" -}}
{{- end -}}