allam-plus-7b / Modelfile.go-template
bnbasel's picture
allam-plus-7b (tools_v2)
788c39a verified
Raw History Blame Contribute Delete
3.12 kB
# Ollama setup for allam-plus-7b with a Go template: for Ollama before 0.40, or with OLLAMA_GO_TEMPLATE=1.
# (written by scripts/make_template.py; the Jinja template inside the GGUF, chat_template.jinja, is the reference)
# ollama create allam-plus -f Modelfile.go-template
#
# It builds the same turns as the reference: the Arabic tool guide and one JSON line per tool in the system turn,
# <tool_call> lines in assistant turns, <tool_result> lines in user turns, same-role turns merged, ALLaM's [INST]
# format around them. One known difference: Go prints each tool's "parameters" (and past calls' arguments) as compact
# JSON in its own key order, where training used "key": value spacing; docs/PHASE4.md has the scores through it.
# Ollama adds the first <s> itself, so the first turn starts with " [INST]"; later turns write <s> explicitly.
FROM ./allam-plus-7b-Q4_K_M.gguf
TEMPLATE """{{- $sys := "" }}
{{- range .Messages }}{{ if eq .Role "system" }}{{ $sys = .Content }}{{ end }}{{ end }}
{{- if .Tools }}
{{- if not $sys }}{{ $sys = "أنت مساعد مفيد ترد باللغة العربية." }}{{ end }}
{{- $sys = printf "%s\n\n%s\n" $sys "يمكنك استخدام الأدوات المدرجة أدناه. لاستدعاء أداة، رد بهذا السطر فقط ولا شيء آخر:\n<tool_call>{\"name\": \"<اسم الأداة>\", \"arguments\": {<الوسائط بصيغة JSON>}}</tool_call>\nلاستدعاء عدة أدوات دفعة واحدة، اكتب سطرًا واحدًا كهذا لكل استدعاء. تعود نتائج الأدوات على شكل <tool_result>...</tool_result>. إذا لم تناسب أي أداة الطلب، أو كان هناك تفصيل مطلوب مفقود، فرد على المستخدم بشكل عادي. الأدوات:" }}
{{- range $i, $t := .Tools }}
{{- if $i }}{{ $sys = printf "%s\n" $sys }}{{ end }}
{{- $sys = printf "%s{\"name\": %s, \"description\": %s, \"parameters\": %s}" $sys (json $t.Function.Name) (json $t.Function.Description) (json $t.Function.Parameters) }}
{{- end }}
{{- end }}
{{- $prev := "" }}
{{- $first := true }}
{{- range .Messages }}
{{- if eq .Role "system" }}{{ continue }}{{ end }}
{{- $role := .Role }}
{{- if eq .Role "tool" }}{{ $role = "user" }}{{ end }}
{{- if .ToolCalls }}{{ $role = "assistant" }}{{ end }}
{{- if eq $role $prev }}
{{- "\n" }}
{{- else }}
{{- if eq $prev "user" }} [/INST]{{ else if eq $prev "assistant" }} </s>{{ end }}
{{- if eq $role "user" }}{{ if not $first }}<s>{{ end }} [INST] {{ if and $first $sys }}<<SYS>>
{{ $sys }}
<</SYS>>
{{ end }}
{{- else }} {{ end }}
{{- $first = false }}
{{- end }}
{{- if eq .Role "tool" }}<tool_result>{{ .Content }}</tool_result>
{{- else if .ToolCalls }}{{ if .Content }}{{ .Content }}
{{ end }}{{ range $j, $c := .ToolCalls }}{{ if $j }}
{{ end }}<tool_call>{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}</tool_call>{{ end }}
{{- else }}{{ .Content }}
{{- end }}
{{- $prev = $role }}
{{- end }}
{{- if eq $prev "user" }} [/INST]{{ end }}"""
PARAMETER stop "</s>"
PARAMETER temperature 0
PARAMETER num_ctx 16384