frob/ glm-5:latest

250 1 month ago

tools thinking
d4979126e2a5 · 1.5kB
{{- $lastUserIdx := -1 }}
{{- range $i, $_ := .Messages }}
{{- if eq .Role "user" }}{{- $lastUserIdx = $i }}{{ end }}
{{- end -}}
[gMASK]<sop>
{{- if or .System .Tools }}<|system|>
{{- 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 }}
{{ json .Function }}
{{ end }}
</tools>
For each function call, output the function name and arguments within <tool_call></tool_call> XML tags using the following JSON format:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{ end }}
{{- if .System }}
{{ .System }}{{ end }}
{{- end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|user|>
{{ .Content }}
{{- else if eq .Role "assistant" }}<|assistant|>
{{- if (and $.IsThinkSet $.Think .Thinking (or $last (gt $i $lastUserIdx))) -}}
<think>{{ .Thinking }}</think>
{{- end }}
{{- if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}
{{- else if eq .Role "tool" }}<|observation|>
<tool_response>
{{ .Content }}
</tool_response>
{{- end }}
{{- if and (ne .Role "assistant") $last }}<|assistant|>{{ if and $.IsThinkSet (not $.Think) }}</think>{{ else }}<think>{{ end }}
{{ end }}
{{- end }}