168 3 weeks ago

專為中華民國台灣語境打造的繁體中文指令微調模型

tools
039e77224ae2 · 2.3kB
{{- $msgs := .Messages -}}
{{- $system := "" -}}
{{- if and (gt (len $msgs) 0) (eq (index $msgs 0).Role "system") -}}
{{- $system = (index $msgs 0).Content -}}
{{- $msgs = (slice $msgs 1) -}}
{{- end -}}
{{- $firstUserPrefix := and (eq (len .Tools) 0) (ne $system "") -}}
{{- $prefixed := false -}}
{{- if .Tools -}}
<start_of_turn>user
{{ if $system }}{{ $system }} {{ end }}You are provided with function signatures within <tools> </tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools:
<tools>
[{{- range $i, $tool := .Tools }}{{- if $i }},{{ end }}{{ printf "{\"function\":%s,\"type\":\"%s\"}" (json $tool.Function) $tool.Type }}{{- end }}]
</tools>
For each function call return a json object with function name and arguments within <tool_call> </tool_call> tags with the following schema:
<tool_call>
{"arguments": <args-dict>, "name": <function-name>}
</tool_call>
{{- if and (gt (len $msgs) 0) (eq (index $msgs 0).Role "user") }}
{{ (index $msgs 0).Content }}{{- $msgs = (slice $msgs 1) -}}{{- end -}}<end_of_turn>
{{- end }}
{{- $inTool := false -}}
{{- range $msgs }}
{{- if eq .Role "tool" }}
{{- if not $inTool }}
<start_of_turn>tool
{{- $inTool = true -}}
{{- end }}
<tool_response>
{{- $c := .Content -}}
{{- if and (ge (len $c) 1) (eq (slice $c 0 1) "[") }}
{{ printf "{'name': '%s', 'content': %s}" .ToolName $c }}
{{- else }}
{{ printf "{'name': '%s', 'content': '%s'}" .ToolName $c }}
{{- end }}
</tool_response>
{{- else }}
{{- if $inTool }}
<end_of_turn>
{{- $inTool = false -}}
{{- end }}
{{- if eq .Role "user" }}
{{- $content := .Content -}}
{{- if and (not $prefixed) $firstUserPrefix }}
{{- $content = (printf "%s\n\n%s" $system $content) -}}
{{- $prefixed = true -}}
{{- end }}
<start_of_turn>user
{{ $content }}<end_of_turn>
{{- else if eq .Role "assistant" }}
<start_of_turn>model
{{- if .ToolCalls }}{{- range .ToolCalls }}
<tool_call>
{"name": "{{ .Function.Name }}", "arguments": {{ json .Function.Arguments }}}
</tool_call>
{{- end }}{{- else }}
{{ .Content }}
{{- end }}<end_of_turn>
{{- end }}
{{- end }}
{{- end }}
{{- if $inTool }}
<end_of_turn>
{{- end }}
<start_of_turn>model