Skip to content

Commit f6d2756

Browse files
authored
ollama: fix mistral-small template (#1343)
1 parent d625b32 commit f6d2756

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/ollama-utils/src/chat-template.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate
8181
stop: "<|END_OF_TURN_TOKEN|>",
8282
}
8383
: undefined,
84+
(ggufTmpl: string) =>
85+
ggufTmpl.match(/Mistral Small 3/) && ggufTmpl.match(/2023-10-01/)
86+
? {
87+
// https://ollama.com/library/mistral-small
88+
// (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)
89+
ollamaTmpl:
90+
'{{- 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) }}</s>\n{{- end }}\n{{- else if .ToolCalls }}[TOOL_CALLS][\n{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}\n{{- end }}]</s>\n{{- end }}\n{{- else if eq .Role "tool" }}[TOOL_RESULTS]{"content": {{ .Content }}}[/TOOL_RESULTS]\n{{- end }}\n{{- end }}',
91+
stop: "[INST]",
92+
}
93+
: undefined,
8494
];
8595

8696
export function convertGGUFTemplateToOllama(

0 commit comments

Comments
 (0)