mirror of
https://github.com/dogkeeper886/ollama37.git
synced 2025-12-11 00:07:07 +00:00
template: preprocess message and collect system
This commit is contained in:
@@ -216,13 +216,11 @@ func TestExecuteWithMessages(t *testing.T) {
|
||||
{"response", `[INST] {{ if .System }}{{ .System }}
|
||||
|
||||
{{ end }}{{ .Prompt }}[/INST] {{ .Response }}`},
|
||||
{"messages", `{{- $system := contents .Messages "system" -}}
|
||||
{{- range $index, $_ := .Messages }}
|
||||
{{- if eq .Role "user" }}[INST] {{ if $system }}{{ $system }}
|
||||
{{- $system = "" }}
|
||||
{"messages", `[INST] {{ if .System }}{{ .System }}
|
||||
|
||||
{{ end }}{{ .Content }}[/INST] {{ else if eq .Role "assistant" }}{{ .Content }}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
{{- range .Messages }}
|
||||
{{- if eq .Role "user" }}{{ .Content }}[/INST] {{ else if eq .Role "assistant" }}{{ .Content }}[INST] {{ end }}
|
||||
{{- end }}`},
|
||||
},
|
||||
Values{
|
||||
@@ -243,13 +241,11 @@ func TestExecuteWithMessages(t *testing.T) {
|
||||
{"response", `[INST] {{ if .System }}{{ .System }}
|
||||
|
||||
{{ end }}{{ .Prompt }}[/INST] {{ .Response }}`},
|
||||
{"messages", `{{- $system := contents .Messages "system" -}}
|
||||
{{- range $index, $_ := .Messages }}
|
||||
{{- if eq .Role "user" }}[INST] {{ if $system }}{{ $system }}
|
||||
{{- $system = "" }}
|
||||
{"messages", `[INST] {{ if .System }}{{ .System }}
|
||||
|
||||
{{ end }}{{ .Content }}[/INST] {{ else if eq .Role "assistant" }}{{ .Content }}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
{{- range .Messages }}
|
||||
{{- if eq .Role "user" }}{{ .Content }}[/INST] {{ else if eq .Role "assistant" }}{{ .Content }}[INST] {{ end }}
|
||||
{{- end }}`},
|
||||
},
|
||||
Values{
|
||||
@@ -363,36 +359,3 @@ Answer: `,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFuncs(t *testing.T) {
|
||||
t.Run("contents", func(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"": "A\n\nB\n\nC\n\nD\n\nE\n\nF",
|
||||
"system": "A\n\nF",
|
||||
"user": "B\n\nE",
|
||||
"assistant": "C\n\nD",
|
||||
}
|
||||
|
||||
s := []*api.Message{
|
||||
{Role: "system", Content: "A"},
|
||||
{Role: "user", Content: "B"},
|
||||
{Role: "assistant", Content: "C"},
|
||||
{Role: "assistant", Content: "D"},
|
||||
{Role: "user", Content: "E"},
|
||||
{Role: "system", Content: "F"},
|
||||
}
|
||||
|
||||
fn, ok := funcs["contents"].(func([]*api.Message, ...string) string)
|
||||
if !ok {
|
||||
t.Fatal("contents is not a function")
|
||||
}
|
||||
|
||||
for k, v := range cases {
|
||||
t.Run(k, func(t *testing.T) {
|
||||
if diff := cmp.Diff(fn(s, k), v); diff != "" {
|
||||
t.Errorf("mismatch (-got +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user