doomgrave/
phi-4:latest

80 4 months ago

phi4:14b, with working tools, quantized to Q2_K and Q3_K_S for GPU with 8gb Vram or less.

tools
7a9b3e46e155 · 1.4kB
{{- /* If System or Tools, provide a system message first. */ -}}
{{- if or .System .Tools }}
<|im_start|>system<|im_sep|>
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
You are a helpful assistant with tool calling capabilities. When you receive tool output, use it to help format your final answer for the user.
{{- end }}
<|im_end|>
{{- end }}
{{- /* Now iterate through .Messages like Phi-4 normally does, but insert logic for Tools. */ -}}
{{- range $i, $msg := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
<|im_start|>{{ $msg.Role }}<|im_sep|>
{{- /* If it's the final user message and Tools exist, prompt for tool-based JSON output. */ -}}
{{- if and (eq $msg.Role "user") $.Tools $last }}
Given the following functions, please respond with a JSON object for a function call. Use this format:
{"name": "<functionName>", "parameters": { "<arg>": "<value>", ... }}
{{ $.Tools }}
{{- end }}
{{ $msg.Content }}
<|im_end|>
{{- /* If it's the final user message, begin assistant reply. */ -}}
{{- if and (eq $msg.Role "user") $last }}
<|im_start|>assistant<|im_sep|>
{{- end }}
{{- /* If role=assistant and there are tool calls, emit them as JSON. */ -}}
{{- if eq $msg.Role "assistant" }}
{{- if $msg.ToolCalls }}
{{- range .ToolCalls }}
{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}