File size: 2,570 Bytes
9dfadfe
 
 
 
2e2b8f8
 
 
 
 
 
 
ee4c9b0
2e2b8f8
ee4c9b0
64b629a
ee4c9b0
64b629a
 
 
 
 
 
 
752eff3
64b629a
 
 
 
 
 
 
 
 
3950347
64b629a
3950347
 
 
64b629a
 
edf99d7
3950347
 
 
 
9ead6fb
edf99d7
 
 
 
64b629a
3070964
 
 
64b629a
 
 
 
3950347
 
 
 
64b629a
3950347
 
64b629a
3950347
 
64b629a
f4db68f
64b629a
f4db68f
 
 
 
 
 
64b629a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end }}
{{- $effort := "" }}
{{- if $.ThinkLevel }}
{{- if or (eq $.ThinkLevel "high") (eq $.ThinkLevel "max") }}{{ $effort = "Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer." }}
{{- else if eq $.ThinkLevel "low" }}{{ $effort = "Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration." }}
{{- end }}
{{- end }}
{{- if or .System .Tools $effort }}<|im_start|>system
{{ if $effort }}{{ $effort }}{{ if or .System .Tools }}

{{ end }}{{ end }}{{ if .System }}{{ .System }}{{ if .Tools }}

{{ end }}{{ 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": {{ json .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|>
{{ end }}
{{- $prevIsTool := false }}
{{- range $i, $_ := .Messages }}
{{- $rest := slice $.Messages $i }}
{{- $last := eq (len $rest) 1 -}}
{{- $nextIsTool := and (gt (len $rest) 1) (eq (index $rest 1).Role "tool") -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}{{ $calls := .ToolCalls }}{{ $blank := or .Content (not $calls) }}<|im_start|>assistant
{{ if $.IsThinkSet -}}
<think>
{{ .Thinking }}
</think>
{{ end -}}
{{ if and $.IsThinkSet $blank }}
{{ end -}}
{{ if .Content }}{{ .Content }}{{ if $calls }}
{{ end }}{{ end }}
{{- if .ToolCalls }}
{{- range .ToolCalls }}
<tool_call>
{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
</tool_call>
{{- end }}
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}
{{- if $prevIsTool }}
{{ else }}<|im_start|>user
{{ end }}<tool_response>
{{ .Content }}
</tool_response>
{{- if not $nextIsTool }}<|im_end|>
{{ end }}
{{- end }}
{{- $prevIsTool = eq .Role "tool" }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ if and $.IsThinkSet (not $.Think) -}}
<think>

</think>

{{ else -}}
<think>
{{ end -}}
{{ end }}
{{- end }}