template
1.4 KB · 50 lines · plaintext Raw
1 {{- if .Messages }}
2 {{- if or .System .Tools }}<|im_start|>system
3 {{- if .System }}
4 {{ .System }}
5 {{- end }}
6 {{- if .Tools }}
7
8 # Tools
9
10 You may call one or more functions to assist with the user query.
11
12 You are provided with function signatures within <tools></tools> XML tags:
13 <tools>
14 {{- range .Tools }}
15 {"type": "function", "function": {{ .Function }}}
16 {{- end }}
17 </tools>
18
19 For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
20 <tool_call>
21 {"name": <function-name>, "arguments": <args-json-object>}
22 </tool_call>
23 {{- end }}<|im_end|>
24 {{ end }}
25 {{- range $i, $_ := .Messages }}
26 {{- $last := eq (len (slice $.Messages $i)) 1 -}}
27 {{- if eq .Role "user" }}<|im_start|>user
28 {{ .Content }}<|im_end|>
29 {{ else if eq .Role "assistant" }}<|im_start|>assistant
30 {{ if .Content }}{{ .Content }}
31 {{- else if .ToolCalls }}<tool_call>
32 {{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
33 {{ end }}</tool_call>
34 {{- end }}{{ if not $last }}<|im_end|>
35 {{ end }}
36 {{- else if eq .Role "tool" }}<|im_start|>user
37 <tool_response>
38 {{ .Content }}
39 </tool_response><|im_end|>
40 {{ end }}
41 {{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
42 {{ end }}
43 {{- end }}
44 {{- else }}
45 {{- if .System }}<|im_start|>system
46 {{ .System }}<|im_end|>
47 {{ end }}{{ if .Prompt }}<|im_start|>user
48 {{ .Prompt }}<|im_end|>
49 {{ end }}<|im_start|>assistant
50 {{ end }}{{ .Response }}{{ if .Response }}<|im_end|>{{ end }}