From 0b4941213a70f06df45fce3cb4c968fec2335f5f Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Tue, 8 Apr 2025 22:13:43 +0200 Subject: [PATCH] ollama: fix mistral-small template --- packages/ollama-utils/src/chat-template.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/ollama-utils/src/chat-template.ts b/packages/ollama-utils/src/chat-template.ts index c9493085ef..7f741db3b6 100644 --- a/packages/ollama-utils/src/chat-template.ts +++ b/packages/ollama-utils/src/chat-template.ts @@ -81,6 +81,16 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate stop: "<|END_OF_TURN_TOKEN|>", } : undefined, + (ggufTmpl: string) => + ggufTmpl.match(/Mistral Small 3/) && ggufTmpl.match(/2023-10-01/) + ? { + // https://ollama.com/library/mistral-small + // (template is edited at some point, so we need manual map to make sure it works, ref commit: https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503/commit/4b8dd8aae705887db5295fcbff4aedbb92d682eb) + ollamaTmpl: + '{{- range $index, $_ := .Messages }}\n{{- if eq .Role "system" }}[SYSTEM_PROMPT]{{ .Content }}[/SYSTEM_PROMPT]\n{{- else if eq .Role "user" }}\n{{- if and (le (len (slice $.Messages $index)) 2) $.Tools }}[AVAILABLE_TOOLS]{{ $.Tools }}[/AVAILABLE_TOOLS]\n{{- end }}[INST]{{ .Content }}[/INST]\n{{- else if eq .Role "assistant" }}\n{{- if .Content }}{{ .Content }}\n{{- if not (eq (len (slice $.Messages $index)) 1) }}\n{{- end }}\n{{- else if .ToolCalls }}[TOOL_CALLS][\n{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}\n{{- end }}]\n{{- end }}\n{{- else if eq .Role "tool" }}[TOOL_RESULTS]{"content": {{ .Content }}}[/TOOL_RESULTS]\n{{- end }}\n{{- end }}', + stop: "[INST]", + } + : undefined, ]; export function convertGGUFTemplateToOllama(