From 57ba38ec722e775bf9c4204472cee4ce1b1b4990 Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Thu, 26 Jun 2025 17:22:39 +0200 Subject: [PATCH] ollama: fix gemma2 template --- packages/ollama-utils/src/chat-template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ollama-utils/src/chat-template.ts b/packages/ollama-utils/src/chat-template.ts index fa65c651d5..3520b0774b 100644 --- a/packages/ollama-utils/src/chat-template.ts +++ b/packages/ollama-utils/src/chat-template.ts @@ -31,7 +31,7 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate ? { // for some reason, gemma2 has weird variants ollamaTmpl: - "user\n{{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}\nmodel\n{{ .Response }}\n", + '{{- range $i, $_ := .Messages }}\n{{- $last := eq (len (slice $.Messages $i)) 1 }}\n{{- if or (eq .Role "user") (eq .Role "system") }}user\n{{ .Content }}\n{{ if $last }}model\n{{ end }}\n{{- else if eq .Role "assistant" }}model\n{{ .Content }}{{ if not $last }}\n{{ end }}\n{{- end }}\n{{- end }}', stop: "", } : undefined,