From 7d67d6f3d97e2ead11ffeb41caf8edc4f1cacb0f Mon Sep 17 00:00:00 2001 From: jmorganca Date: Fri, 19 Jul 2024 18:21:22 -0700 Subject: [PATCH] template: fix mistral not adding system prompt if assistant is last message --- server/testdata/tools/mistral.gotmpl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/testdata/tools/mistral.gotmpl b/server/testdata/tools/mistral.gotmpl index b08d6c2c1..0e88e6200 100644 --- a/server/testdata/tools/mistral.gotmpl +++ b/server/testdata/tools/mistral.gotmpl @@ -1,11 +1,12 @@ {{- range $index, $_ := .Messages }} {{- if eq .Role "user" }} -{{- if and (eq (len (slice $.Messages $index)) 1) $.Tools }}[AVAILABLE_TOOLS] {{ $.Tools }}[/AVAILABLE_TOOLS] -{{- end }}[INST] {{ if and (eq (len (slice $.Messages $index)) 1) $.System }}{{ $.System }} +{{- $last := (or (eq (len (slice $.Messages $index)) 1) (eq (len (slice $.Messages $index)) 2)) }} +{{- if and $last $.Tools }}[AVAILABLE_TOOLS] {{ $.Tools }}[/AVAILABLE_TOOLS] +{{- end }}[INST] {{ if and $last $.System }}{{ $.System }} {{ end }}{{ .Content }}[/INST] {{- else if eq .Role "assistant" }} -{{- if .Content }} {{ .Content }} +{{- if .Content }} {{ .Content }}{{ if not (eq (len (slice $.Messages $index)) 1) }}{{ end }} {{- else if .ToolCalls }}[TOOL_CALLS] [ {{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}} {{- end }}]