Browse Source

update named templates

Michael Yang 10 months ago
parent
commit
fb6cbc02fb
75 changed files with 611 additions and 27 deletions
  1. 2 1
      go.mod
  2. 2 2
      server/routes_create_test.go
  3. 8 1
      template/alfred.gotmpl
  4. 13 1
      template/alpaca.gotmpl
  5. 10 1
      template/chatml.gotmpl
  6. 13 1
      template/chatqa.gotmpl
  7. 12 1
      template/codellama-70b-instruct.gotmpl
  8. 11 1
      template/falcon-instruct.gotmpl
  9. 13 1
      template/gemma-instruct.gotmpl
  10. 15 1
      template/granite-instruct.gotmpl
  11. 14 1
      template/llama2-chat.gotmpl
  12. 13 1
      template/llama3-instruct.gotmpl
  13. 14 1
      template/magicoder.gotmpl
  14. 9 6
      template/mistral-instruct.gotmpl
  15. 11 1
      template/openchat.gotmpl
  16. 10 1
      template/phi-3.gotmpl
  17. 15 1
      template/solar-instruct.gotmpl
  18. 15 0
      template/starcoder2-instruct.gotmpl
  19. 67 2
      template/template_test.go
  20. 1 0
      template/testdata/alfred.gotmpl/system-user-assistant-user
  21. 1 0
      template/testdata/alfred.gotmpl/user
  22. 1 0
      template/testdata/alfred.gotmpl/user-assistant-user
  23. 10 0
      template/testdata/alpaca.gotmpl/system-user-assistant-user
  24. 4 0
      template/testdata/alpaca.gotmpl/user
  25. 10 0
      template/testdata/alpaca.gotmpl/user-assistant-user
  26. 9 0
      template/testdata/chatml.gotmpl/system-user-assistant-user
  27. 3 0
      template/testdata/chatml.gotmpl/user
  28. 7 0
      template/testdata/chatml.gotmpl/user-assistant-user
  29. 9 0
      template/testdata/chatqa.gotmpl/system-user-assistant-user
  30. 3 0
      template/testdata/chatqa.gotmpl/user
  31. 7 0
      template/testdata/chatqa.gotmpl/user-assistant-user
  32. 11 0
      template/testdata/codellama-70b-instruct.gotmpl/system-user-assistant-user
  33. 5 0
      template/testdata/codellama-70b-instruct.gotmpl/user
  34. 9 0
      template/testdata/codellama-70b-instruct.gotmpl/user-assistant-user
  35. 8 0
      template/testdata/falcon-instruct.gotmpl/system-user-assistant-user
  36. 3 0
      template/testdata/falcon-instruct.gotmpl/user
  37. 7 0
      template/testdata/falcon-instruct.gotmpl/user-assistant-user
  38. 8 0
      template/testdata/gemma-instruct.gotmpl/system-user-assistant-user
  39. 3 0
      template/testdata/gemma-instruct.gotmpl/user
  40. 7 0
      template/testdata/gemma-instruct.gotmpl/user-assistant-user
  41. 13 0
      template/testdata/granite-instruct.gotmpl/system-user-assistant-user
  42. 4 0
      template/testdata/granite-instruct.gotmpl/user
  43. 10 0
      template/testdata/granite-instruct.gotmpl/user-assistant-user
  44. 5 0
      template/testdata/llama2-chat.gotmpl/system-user-assistant-user
  45. 3 0
      template/testdata/llama2-chat.gotmpl/user
  46. 3 0
      template/testdata/llama2-chat.gotmpl/user-assistant-user
  47. 10 0
      template/testdata/llama3-instruct.gotmpl/system-user-assistant-user
  48. 4 0
      template/testdata/llama3-instruct.gotmpl/user
  49. 8 0
      template/testdata/llama3-instruct.gotmpl/user-assistant-user
  50. 12 0
      template/testdata/magicoder.gotmpl/system-user-assistant-user
  51. 4 0
      template/testdata/magicoder.gotmpl/user
  52. 10 0
      template/testdata/magicoder.gotmpl/user-assistant-user
  53. 2 0
      template/testdata/mistral-instruct.gotmpl/system-user-assistant-user
  54. 1 0
      template/testdata/mistral-instruct.gotmpl/user
  55. 1 0
      template/testdata/mistral-instruct.gotmpl/user-assistant-user
  56. 1 0
      template/testdata/openchat.gotmpl/system-user-assistant-user
  57. 1 0
      template/testdata/openchat.gotmpl/user
  58. 1 0
      template/testdata/openchat.gotmpl/user-assistant-user
  59. 9 0
      template/testdata/phi-3.gotmpl/system-user-assistant-user
  60. 3 0
      template/testdata/phi-3.gotmpl/user
  61. 7 0
      template/testdata/phi-3.gotmpl/user-assistant-user
  62. 13 0
      template/testdata/solar-instruct.gotmpl/system-user-assistant-user
  63. 4 0
      template/testdata/solar-instruct.gotmpl/user
  64. 10 0
      template/testdata/solar-instruct.gotmpl/user-assistant-user
  65. 12 0
      template/testdata/starcoder2-instruct.gotmpl/system-user-assistant-user
  66. 4 0
      template/testdata/starcoder2-instruct.gotmpl/user
  67. 10 0
      template/testdata/starcoder2-instruct.gotmpl/user-assistant-user
  68. 6 0
      template/testdata/vicuna.gotmpl/system-user-assistant-user
  69. 2 0
      template/testdata/vicuna.gotmpl/user
  70. 4 0
      template/testdata/vicuna.gotmpl/user-assistant-user
  71. 9 0
      template/testdata/zephyr.gotmpl/system-user-assistant-user
  72. 3 0
      template/testdata/zephyr.gotmpl/user
  73. 7 0
      template/testdata/zephyr.gotmpl/user-assistant-user
  74. 12 1
      template/vicuna.gotmpl
  75. 10 1
      template/zephyr.gotmpl

+ 2 - 1
go.mod

@@ -18,6 +18,7 @@ require (
 require (
 	github.com/agnivade/levenshtein v1.1.1
 	github.com/d4l3k/go-bfloat16 v0.0.0-20211005043715-690c3bdd05f1
+	github.com/google/go-cmp v0.6.0
 	github.com/mattn/go-runewidth v0.0.14
 	github.com/nlpodyssey/gopickle v0.3.0
 	github.com/pdevine/tensor v0.0.0-20240510204454-f88f4562727c
@@ -71,7 +72,7 @@ require (
 	golang.org/x/net v0.25.0 // indirect
 	golang.org/x/sys v0.20.0
 	golang.org/x/term v0.20.0
-	golang.org/x/text v0.15.0 // indirect
+	golang.org/x/text v0.15.0
 	google.golang.org/protobuf v1.34.1
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 )

+ 2 - 2
server/routes_create_test.go

@@ -545,9 +545,9 @@ func TestCreateDetectTemplate(t *testing.T) {
 		}
 
 		checkFileExists(t, filepath.Join(p, "blobs", "*"), []string{
-			filepath.Join(p, "blobs", "sha256-2f8e594e6f34b1b4d36a246628eeb3365ce442303d656f1fcc69e821722acea0"),
-			filepath.Join(p, "blobs", "sha256-542b217f179c7825eeb5bca3c77d2b75ed05bafbd3451d9188891a60a85337c6"),
 			filepath.Join(p, "blobs", "sha256-553c4a3f747b3d22a4946875f1cc8ed011c2930d83f864a0c7265f9ec0a20413"),
+			filepath.Join(p, "blobs", "sha256-9512c372dfc7d84d6065b8dd2b601aeed8cc1a78e7a7aa784a42fff37f5524b7"),
+			filepath.Join(p, "blobs", "sha256-b8b78cb8c6eefd14c06f1af042e6161255bf87bbf2dd14fce57cdac893db8139"),
 		})
 	})
 

+ 8 - 1
template/alfred.gotmpl

@@ -1 +1,8 @@
-{{ if .System }}<start_system>{{ .System }}<end_message>{{ end }}{{ if .Prompt }}<start_user>{{ .Prompt }}<end_message>{{ end }}<start_assistant>{{ .Response }}<end_message>
+{{- if .Messages }}
+{{- if .System }}<start_system>{{ .System }}<end_message>
+{{- end }}
+{{- range .Messages }}<start_{{ .Role }}>{{ .Content }}<end_message>
+{{- end }}<start_assistant>
+{{- else }}
+{{ if .System }}<start_system>{{ .System }}<end_message>{{ end }}{{ if .Prompt }}<start_user>{{ .Prompt }}<end_message>{{ end }}<start_assistant>{{ .Response }}<end_message>
+{{- end }}

+ 13 - 1
template/alpaca.gotmpl

@@ -1,7 +1,19 @@
+{{- if .Messages }}
+{{- if .System }}{{ .System }}
+{{- end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}### Instruction:
+{{- else if eq .Role "assistant" }}### Response:
+{{- end }}
+{{ .Content }}
+
+{{ end }}### Response:
+{{ else }}
 {{ if .System }}{{ .System }}
 
 {{ end }}{{ if .Prompt }}### Instruction:
 {{ .Prompt }}
 
 {{ end }}### Response:
-{{ .Response }}
+{{ .Response }}
+{{- end }}

+ 10 - 1
template/chatml.gotmpl

@@ -1,6 +1,15 @@
+{{- if .Messages }}
+{{- if .System }}<|im_start|>system
+{{ .System }}<|im_end|>
+{{ end }}
+{{- range .Messages }}<|im_start|>{{ .Role }}
+{{ .Content }}<|im_end|>
+{{ end }}<|im_start|>assistant
+{{ else }}
 {{ if .System }}<|im_start|>system
 {{ .System }}<|im_end|>
 {{ end }}{{ if .Prompt }}<|im_start|>user
 {{ .Prompt }}<|im_end|>
 {{ end }}<|im_start|>assistant
-{{ .Response }}<|im_end|>
+{{ .Response }}<|im_end|>
+{{- end }}

+ 13 - 1
template/chatqa.gotmpl

@@ -1,5 +1,17 @@
+{{- if .Messages }}
+{{- if .System }}System: {{ .System }}
+
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}User:
+{{- else if eq .Role "assistant" }}Assistant:
+{{- end }} {{ .Content }}
+
+{{ end }}Assistant:
+{{- else }}
 {{ if .System }}System: {{ .System }}
 
 {{ end }}{{ if .Prompt }}User: {{ .Prompt }}
 
-{{ end }}Assistant: <|begin_of_text|>{{ .Response }}
+{{ end }}Assistant: <|begin_of_text|>{{ .Response }}
+{{- end }}

+ 12 - 1
template/codellama-70b-instruct.gotmpl

@@ -1,3 +1,13 @@
+{{- if .Messages }}
+{{- if .System }}Source: system
+
+ {{ .System }} <step> {{ end }}
+{{- range .Messages }}Source: {{ .Role }}
+
+ {{ .Content }} <step> {{ end }}Source: assistant
+Destination: user
+
+{{ else }}
 {{ if .System }} Source: system
 
  {{ .System }} <step>{{ end }} Source: user
@@ -5,4 +15,5 @@
  {{ .Prompt }} <step> Source: assistant
 Destination: user
 
- {{ .Response }}<step>
+ {{ .Response }}<step>
+{{- end }}

+ 11 - 1
template/falcon-instruct.gotmpl

@@ -1,3 +1,13 @@
+{{- if .Messages }}
+{{- if .System }}System: {{ .System }}
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}User:
+{{ else if eq .Role "assistant" }}Falcon:
+{{ end }}{{ .Content }}
+{{ end }}Falcon:
+{{ else }}
 {{ if .System }}{{ .System }}
 {{ end }}{{ if .Prompt }}User: {{ .Prompt }}
-{{ end }}Assistant: {{ .Response }}
+{{ end }}Assistant: {{ .Response }}
+{{- end }}

+ 13 - 1
template/gemma-instruct.gotmpl

@@ -1,4 +1,16 @@
+{{- if .Messages }}
+{{- range $index, $_ := .Messages }}<start_of_turn>
+{{- if eq .Role "user" }}user
+{{- if and $.System (eq $index 0) }}
+{{ $.System }}
+{{- end }}
+{{- else if eq .Role "assistant" }}model
+{{- end }}
+{{ .Content }}<end_of_turn>
+{{ end }}<start_of_turn>model
+{{ else }}
 <start_of_turn>user
 {{ if .System }}{{ .System }} {{ end }}{{ .Prompt }}<end_of_turn>
 <start_of_turn>model
-{{ .Response }}<end_of_turn>
+{{ .Response }}<end_of_turn>
+{{- end }}

+ 15 - 1
template/granite-instruct.gotmpl

@@ -1,3 +1,16 @@
+{{- if .Messages }}
+{{- if .System }}System:
+{{ .System }}
+
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}Question:
+{{- else if eq .Role "assistant" }}Answer:
+{{- end }}
+{{ .Content }}
+
+{{ end }}Answer:
+{{ else }}
 {{ if .System }}
 System:
 {{ .System }}
@@ -6,4 +19,5 @@ System:
 {{ .Prompt }}
 
 {{ end }}Answer:
-{{ .Response }}
+{{ .Response }}
+{{- end }}

+ 14 - 1
template/llama2-chat.gotmpl

@@ -1,3 +1,16 @@
+{{- if .Messages }}
+{{- range $index, $_ := .Messages }}
+{{- if eq .Role "user" }}[INST] {{ if eq $index 0 }}<<SYS>>
+{{- if $.System }}
+{{ $.System }}
+{{ end }}<</SYS>>
+
+{{ end }}{{ .Content }}
+{{- else }} [/INST] {{ .Content }}</s><s>
+{{- end }}
+{{- end }} [/INST]
+{{- else }}
 [INST] <<SYS>>{{ .System }}<</SYS>>
 
-{{ .Prompt }} [/INST] {{ .Response }}
+{{ .Prompt }} [/INST] {{ .Response }}
+{{- end }}

+ 13 - 1
template/llama3-instruct.gotmpl

@@ -1,7 +1,19 @@
+{{- if .Messages }}
+{{- if .System }}<|start_header_id|>system<|end_header_id|>
+
+{{ .System }}<|eot_id|>
+{{- end }}
+{{- range .Messages }}<|start_header_id|>{{ .Role }}<|end_header_id|>
+
+{{ .Content }}<|eot_id|>
+{{- end }}<|start_header_id|>assistant<|end_header_id|>
+
+{{ else }}
 {{ if .System }}<|start_header_id|>system<|end_header_id|>
 
 {{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
 
 {{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
 
-{{ .Response }}<|eot_id|>
+{{ .Response }}<|eot_id|>
+{{- end }}

+ 14 - 1
template/magicoder.gotmpl

@@ -1,7 +1,20 @@
+{{- if .Messages }}
+{{- if .System }}{{ .System }}
+
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}@@ Instruction
+{{- else if eq .Role "assistant" }}@@ Response
+{{- end }}
+{{ .Content }}
+
+{{ end }}@@ Response
+{{ else }}
 {{ if .System }}{{ .System }}
 
 {{ end }}{{ if .Prompt }}@@ Instruction
 {{ .Prompt }}
 
 {{ end }}@@ Response
-{{ .Response }}
+{{ .Response }}
+{{- end }}

+ 9 - 6
template/mistral-instruct.gotmpl

@@ -1,6 +1,9 @@
-{{ if .System }}<|im_start|>system
-{{ .System }}<|im_end|>
-{{ end }}{{ if .Prompt }}<|im_start|>user
-{{ .Prompt }}<|im_end|>
-{{ end }}<|im_start|>assistant
-{{ .Response }}<|im_end|>
+{{- if .Messages }}
+{{- range $index, $_ := .Messages }}
+{{- if eq .Role "user" }}[INST] {{ if and $.System (eq (len (slice $.Messages $index)) 1) }}{{ $.System }}
+{{ end }}{{ .Content }}
+{{- else if eq .Role "assistant" }}[/INST] {{ .Content }}</s>
+{{- end }}
+{{- end }}[/INST]
+{{- else }}[INST] {{ if .System }}{{ .System }} {{ end }}{{ .Prompt }} [/INST] {{ .Response }}
+{{- end }}

+ 11 - 1
template/openchat.gotmpl

@@ -1 +1,11 @@
-{{ .System }}<|end_of_turn|>GPT4 Correct User: {{ .Prompt }}<|end_of_turn|>GPT4 Correct Assistant: {{ .Response }}<|end_of_turn|>
+{{- if .Messages }}
+{{- if .System }}GPT Correct System: {{ .System }}<|end_of_turn|>
+{{- end }}
+{{- range .Messages }}GPT Correct
+{{- if eq .Role "user" }} User:
+{{- else if eq .Role "assistant" }} Assistant:
+{{- end }} {{ .Content }}<|end_of_turn|>
+{{- end }}GPT Correct Assistant:
+{{- else }}
+{{ .System }}<|end_of_turn|>GPT4 Correct User: {{ .Prompt }}<|end_of_turn|>GPT4 Correct Assistant: {{ .Response }}<|end_of_turn|>
+{{- end }}

+ 10 - 1
template/phi-3.gotmpl

@@ -1,6 +1,15 @@
+{{- if .Messages }}
+{{- if .System }}<|system|>
+{{ .System }}<|end|>
+{{ end }}
+{{- range .Messages }}<|{{ .Role }}|>
+{{ .Content }}<|end|>
+{{ end }}<|assistant|>
+{{ else }}
 {{ if .System }}<|system|>
 {{ .System }}<|end|>
 {{ end }}{{ if .Prompt }}<|user|>
 {{ .Prompt }}<|end|>
 {{ end }}<|assistant|>
-{{ .Response }}<|end|>
+{{ .Response }}<|end|>
+{{- end }}

+ 15 - 1
template/solar-instruct.gotmpl

@@ -1,3 +1,16 @@
+{{- if .Messages }}
+{{- if .System }}### System:
+{{ .System }}
+
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}### User:
+{{ .Content }}
+{{ else if eq .Role "assistant" }}### Assistant:
+{{ .Content }}</s>
+{{ end }}
+{{ end }}### Assistant:
+{{ else }}
 {{ if .System }}### System:
 {{ .System }}
 
@@ -5,4 +18,5 @@
 {{ .Prompt }}
 
 {{ end }}### Assistant:
-{{ .Response }}
+{{ .Response }}
+{{- end }}

+ 15 - 0
template/starcoder2-instruct.gotmpl

@@ -1,3 +1,17 @@
+{{- if .Messages }}
+{{- if .System }}{{ .System }}
+
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}### Instruction
+{{ .Content }}
+
+{{ else if eq .Role "assistant" }}### Response
+{{ .Content }}<|endoftext|>
+
+{{ end }}
+{{- end }}### Response
+{{ else }}
 {{ if .System }}{{ .System }}
 
 {{ end }}{{ if .Prompt }}### Instruction
@@ -7,3 +21,4 @@
 {{ end }}### Response
 {{ .Response }}<|endoftext|>
 
+{{- end }}

+ 67 - 2
template/template_test.go

@@ -8,9 +8,10 @@ import (
 	"os"
 	"path/filepath"
 	"slices"
+	"strings"
 	"testing"
-	"text/template"
 
+	"github.com/google/go-cmp/cmp"
 	"github.com/ollama/ollama/api"
 	"github.com/ollama/ollama/llm"
 )
@@ -47,7 +48,7 @@ func TestNamed(t *testing.T) {
 					t.Fatal(err)
 				}
 
-				tmpl, err := template.New(s).Parse(b.String())
+				tmpl, err := Parse(b.String())
 				if err != nil {
 					t.Fatal(err)
 				}
@@ -60,6 +61,70 @@ func TestNamed(t *testing.T) {
 	}
 }
 
+func TestTemplate(t *testing.T) {
+	cases := make(map[string][]api.Message)
+	for _, mm := range [][]api.Message{
+		{
+			{Role: "user", Content: "Hello, how are you?"},
+		},
+		{
+			{Role: "user", Content: "Hello, how are you?"},
+			{Role: "assistant", Content: "I'm doing great. How can I help you today?"},
+			{Role: "user", Content: "I'd like to show off how chat templating works!"},
+		},
+		{
+			{Role: "system", Content: "You are a helpful assistant."},
+			{Role: "user", Content: "Hello, how are you?"},
+			{Role: "assistant", Content: "I'm doing great. How can I help you today?"},
+			{Role: "user", Content: "I'd like to show off how chat templating works!"},
+		},
+	} {
+		var roles []string
+		for _, m := range mm {
+			roles = append(roles, m.Role)
+		}
+
+		cases[strings.Join(roles, "-")] = mm
+	}
+
+	matches, err := filepath.Glob("*.gotmpl")
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	for _, match := range matches {
+		t.Run(match, func(t *testing.T) {
+			bts, err := os.ReadFile(match)
+			if err != nil {
+				t.Fatal(err)
+			}
+
+			tmpl, err := Parse(string(bts))
+			if err != nil {
+				t.Fatal(err)
+			}
+
+			for n, tt := range cases {
+				t.Run(n, func(t *testing.T) {
+					var actual bytes.Buffer
+					if err := tmpl.Execute(&actual, Values{Messages: tt}); err != nil {
+						t.Fatal(err)
+					}
+
+					expect, err := os.ReadFile(filepath.Join("testdata", match, n))
+					if err != nil {
+						t.Fatal(err)
+					}
+
+					if diff := cmp.Diff(actual.Bytes(), expect); diff != "" {
+						t.Errorf("mismatch (-got +want):\n%s", diff)
+					}
+				})
+			}
+		})
+	}
+}
+
 func TestParse(t *testing.T) {
 	cases := []struct {
 		template string

+ 1 - 0
template/testdata/alfred.gotmpl/system-user-assistant-user

@@ -0,0 +1 @@
+<start_system>You are a helpful assistant.<end_message><start_user>Hello, how are you?<end_message><start_assistant>I'm doing great. How can I help you today?<end_message><start_user>I'd like to show off how chat templating works!<end_message><start_assistant>

+ 1 - 0
template/testdata/alfred.gotmpl/user

@@ -0,0 +1 @@
+<start_user>Hello, how are you?<end_message><start_assistant>

+ 1 - 0
template/testdata/alfred.gotmpl/user-assistant-user

@@ -0,0 +1 @@
+<start_user>Hello, how are you?<end_message><start_assistant>I'm doing great. How can I help you today?<end_message><start_user>I'd like to show off how chat templating works!<end_message><start_assistant>

+ 10 - 0
template/testdata/alpaca.gotmpl/system-user-assistant-user

@@ -0,0 +1,10 @@
+You are a helpful assistant.### Instruction:
+Hello, how are you?
+
+### Response:
+I'm doing great. How can I help you today?
+
+### Instruction:
+I'd like to show off how chat templating works!
+
+### Response:

+ 4 - 0
template/testdata/alpaca.gotmpl/user

@@ -0,0 +1,4 @@
+### Instruction:
+Hello, how are you?
+
+### Response:

+ 10 - 0
template/testdata/alpaca.gotmpl/user-assistant-user

@@ -0,0 +1,10 @@
+### Instruction:
+Hello, how are you?
+
+### Response:
+I'm doing great. How can I help you today?
+
+### Instruction:
+I'd like to show off how chat templating works!
+
+### Response:

+ 9 - 0
template/testdata/chatml.gotmpl/system-user-assistant-user

@@ -0,0 +1,9 @@
+<|im_start|>system
+You are a helpful assistant.<|im_end|>
+<|im_start|>user
+Hello, how are you?<|im_end|>
+<|im_start|>assistant
+I'm doing great. How can I help you today?<|im_end|>
+<|im_start|>user
+I'd like to show off how chat templating works!<|im_end|>
+<|im_start|>assistant

+ 3 - 0
template/testdata/chatml.gotmpl/user

@@ -0,0 +1,3 @@
+<|im_start|>user
+Hello, how are you?<|im_end|>
+<|im_start|>assistant

+ 7 - 0
template/testdata/chatml.gotmpl/user-assistant-user

@@ -0,0 +1,7 @@
+<|im_start|>user
+Hello, how are you?<|im_end|>
+<|im_start|>assistant
+I'm doing great. How can I help you today?<|im_end|>
+<|im_start|>user
+I'd like to show off how chat templating works!<|im_end|>
+<|im_start|>assistant

+ 9 - 0
template/testdata/chatqa.gotmpl/system-user-assistant-user

@@ -0,0 +1,9 @@
+System: You are a helpful assistant.
+
+User: Hello, how are you?
+
+Assistant: I'm doing great. How can I help you today?
+
+User: I'd like to show off how chat templating works!
+
+Assistant:

+ 3 - 0
template/testdata/chatqa.gotmpl/user

@@ -0,0 +1,3 @@
+User: Hello, how are you?
+
+Assistant:

+ 7 - 0
template/testdata/chatqa.gotmpl/user-assistant-user

@@ -0,0 +1,7 @@
+User: Hello, how are you?
+
+Assistant: I'm doing great. How can I help you today?
+
+User: I'd like to show off how chat templating works!
+
+Assistant:

+ 11 - 0
template/testdata/codellama-70b-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,11 @@
+Source: system
+
+ You are a helpful assistant. <step> Source: user
+
+ Hello, how are you? <step> Source: assistant
+
+ I'm doing great. How can I help you today? <step> Source: user
+
+ I'd like to show off how chat templating works! <step> Source: assistant
+Destination: user
+

+ 5 - 0
template/testdata/codellama-70b-instruct.gotmpl/user

@@ -0,0 +1,5 @@
+Source: user
+
+ Hello, how are you? <step> Source: assistant
+Destination: user
+

+ 9 - 0
template/testdata/codellama-70b-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,9 @@
+Source: user
+
+ Hello, how are you? <step> Source: assistant
+
+ I'm doing great. How can I help you today? <step> Source: user
+
+ I'd like to show off how chat templating works! <step> Source: assistant
+Destination: user
+

+ 8 - 0
template/testdata/falcon-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,8 @@
+System: You are a helpful assistant.
+User:
+Hello, how are you?
+Falcon:
+I'm doing great. How can I help you today?
+User:
+I'd like to show off how chat templating works!
+Falcon:

+ 3 - 0
template/testdata/falcon-instruct.gotmpl/user

@@ -0,0 +1,3 @@
+User:
+Hello, how are you?
+Falcon:

+ 7 - 0
template/testdata/falcon-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,7 @@
+User:
+Hello, how are you?
+Falcon:
+I'm doing great. How can I help you today?
+User:
+I'd like to show off how chat templating works!
+Falcon:

+ 8 - 0
template/testdata/gemma-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,8 @@
+<start_of_turn>user
+You are a helpful assistant.
+Hello, how are you?<end_of_turn>
+<start_of_turn>model
+I'm doing great. How can I help you today?<end_of_turn>
+<start_of_turn>user
+I'd like to show off how chat templating works!<end_of_turn>
+<start_of_turn>model

+ 3 - 0
template/testdata/gemma-instruct.gotmpl/user

@@ -0,0 +1,3 @@
+<start_of_turn>user
+Hello, how are you?<end_of_turn>
+<start_of_turn>model

+ 7 - 0
template/testdata/gemma-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,7 @@
+<start_of_turn>user
+Hello, how are you?<end_of_turn>
+<start_of_turn>model
+I'm doing great. How can I help you today?<end_of_turn>
+<start_of_turn>user
+I'd like to show off how chat templating works!<end_of_turn>
+<start_of_turn>model

+ 13 - 0
template/testdata/granite-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,13 @@
+System:
+You are a helpful assistant.
+
+Question:
+Hello, how are you?
+
+Answer:
+I'm doing great. How can I help you today?
+
+Question:
+I'd like to show off how chat templating works!
+
+Answer:

+ 4 - 0
template/testdata/granite-instruct.gotmpl/user

@@ -0,0 +1,4 @@
+Question:
+Hello, how are you?
+
+Answer:

+ 10 - 0
template/testdata/granite-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,10 @@
+Question:
+Hello, how are you?
+
+Answer:
+I'm doing great. How can I help you today?
+
+Question:
+I'd like to show off how chat templating works!
+
+Answer:

+ 5 - 0
template/testdata/llama2-chat.gotmpl/system-user-assistant-user

@@ -0,0 +1,5 @@
+[INST] <<SYS>>
+You are a helpful assistant.
+<</SYS>>
+
+Hello, how are you? [/INST] I'm doing great. How can I help you today?</s><s>[INST] I'd like to show off how chat templating works! [/INST]

+ 3 - 0
template/testdata/llama2-chat.gotmpl/user

@@ -0,0 +1,3 @@
+[INST] <<SYS>><</SYS>>
+
+Hello, how are you? [/INST]

+ 3 - 0
template/testdata/llama2-chat.gotmpl/user-assistant-user

@@ -0,0 +1,3 @@
+[INST] <<SYS>><</SYS>>
+
+Hello, how are you? [/INST] I'm doing great. How can I help you today?</s><s>[INST] I'd like to show off how chat templating works! [/INST]

+ 10 - 0
template/testdata/llama3-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,10 @@
+<|start_header_id|>system<|end_header_id|>
+
+You are a helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>
+
+Hello, how are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+
+I'm doing great. How can I help you today?<|eot_id|><|start_header_id|>user<|end_header_id|>
+
+I'd like to show off how chat templating works!<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+

+ 4 - 0
template/testdata/llama3-instruct.gotmpl/user

@@ -0,0 +1,4 @@
+<|start_header_id|>user<|end_header_id|>
+
+Hello, how are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+

+ 8 - 0
template/testdata/llama3-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,8 @@
+<|start_header_id|>user<|end_header_id|>
+
+Hello, how are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+
+I'm doing great. How can I help you today?<|eot_id|><|start_header_id|>user<|end_header_id|>
+
+I'd like to show off how chat templating works!<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+

+ 12 - 0
template/testdata/magicoder.gotmpl/system-user-assistant-user

@@ -0,0 +1,12 @@
+You are a helpful assistant.
+
+@@ Instruction
+Hello, how are you?
+
+@@ Response
+I'm doing great. How can I help you today?
+
+@@ Instruction
+I'd like to show off how chat templating works!
+
+@@ Response

+ 4 - 0
template/testdata/magicoder.gotmpl/user

@@ -0,0 +1,4 @@
+@@ Instruction
+Hello, how are you?
+
+@@ Response

+ 10 - 0
template/testdata/magicoder.gotmpl/user-assistant-user

@@ -0,0 +1,10 @@
+@@ Instruction
+Hello, how are you?
+
+@@ Response
+I'm doing great. How can I help you today?
+
+@@ Instruction
+I'd like to show off how chat templating works!
+
+@@ Response

+ 2 - 0
template/testdata/mistral-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,2 @@
+[INST] Hello, how are you?[/INST] I'm doing great. How can I help you today?</s>[INST] You are a helpful assistant.
+I'd like to show off how chat templating works![/INST]

+ 1 - 0
template/testdata/mistral-instruct.gotmpl/user

@@ -0,0 +1 @@
+[INST] Hello, how are you?[/INST]

+ 1 - 0
template/testdata/mistral-instruct.gotmpl/user-assistant-user

@@ -0,0 +1 @@
+[INST] Hello, how are you?[/INST] I'm doing great. How can I help you today?</s>[INST] I'd like to show off how chat templating works![/INST]

+ 1 - 0
template/testdata/openchat.gotmpl/system-user-assistant-user

@@ -0,0 +1 @@
+GPT Correct System: You are a helpful assistant.<|end_of_turn|>GPT Correct User: Hello, how are you?<|end_of_turn|>GPT Correct Assistant: I'm doing great. How can I help you today?<|end_of_turn|>GPT Correct User: I'd like to show off how chat templating works!<|end_of_turn|>GPT Correct Assistant:

+ 1 - 0
template/testdata/openchat.gotmpl/user

@@ -0,0 +1 @@
+GPT Correct User: Hello, how are you?<|end_of_turn|>GPT Correct Assistant:

+ 1 - 0
template/testdata/openchat.gotmpl/user-assistant-user

@@ -0,0 +1 @@
+GPT Correct User: Hello, how are you?<|end_of_turn|>GPT Correct Assistant: I'm doing great. How can I help you today?<|end_of_turn|>GPT Correct User: I'd like to show off how chat templating works!<|end_of_turn|>GPT Correct Assistant:

+ 9 - 0
template/testdata/phi-3.gotmpl/system-user-assistant-user

@@ -0,0 +1,9 @@
+<|system|>
+You are a helpful assistant.<|end|>
+<|user|>
+Hello, how are you?<|end|>
+<|assistant|>
+I'm doing great. How can I help you today?<|end|>
+<|user|>
+I'd like to show off how chat templating works!<|end|>
+<|assistant|>

+ 3 - 0
template/testdata/phi-3.gotmpl/user

@@ -0,0 +1,3 @@
+<|user|>
+Hello, how are you?<|end|>
+<|assistant|>

+ 7 - 0
template/testdata/phi-3.gotmpl/user-assistant-user

@@ -0,0 +1,7 @@
+<|user|>
+Hello, how are you?<|end|>
+<|assistant|>
+I'm doing great. How can I help you today?<|end|>
+<|user|>
+I'd like to show off how chat templating works!<|end|>
+<|assistant|>

+ 13 - 0
template/testdata/solar-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,13 @@
+### System:
+You are a helpful assistant.
+
+### User:
+Hello, how are you?
+
+### Assistant:
+I'm doing great. How can I help you today?</s>
+
+### User:
+I'd like to show off how chat templating works!
+
+### Assistant:

+ 4 - 0
template/testdata/solar-instruct.gotmpl/user

@@ -0,0 +1,4 @@
+### User:
+Hello, how are you?
+
+### Assistant:

+ 10 - 0
template/testdata/solar-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,10 @@
+### User:
+Hello, how are you?
+
+### Assistant:
+I'm doing great. How can I help you today?</s>
+
+### User:
+I'd like to show off how chat templating works!
+
+### Assistant:

+ 12 - 0
template/testdata/starcoder2-instruct.gotmpl/system-user-assistant-user

@@ -0,0 +1,12 @@
+You are a helpful assistant.
+
+### Instruction
+Hello, how are you?
+
+### Response
+I'm doing great. How can I help you today?<|endoftext|>
+
+### Instruction
+I'd like to show off how chat templating works!
+
+### Response

+ 4 - 0
template/testdata/starcoder2-instruct.gotmpl/user

@@ -0,0 +1,4 @@
+### Instruction
+Hello, how are you?
+
+### Response

+ 10 - 0
template/testdata/starcoder2-instruct.gotmpl/user-assistant-user

@@ -0,0 +1,10 @@
+### Instruction
+Hello, how are you?
+
+### Response
+I'm doing great. How can I help you today?<|endoftext|>
+
+### Instruction
+I'd like to show off how chat templating works!
+
+### Response

+ 6 - 0
template/testdata/vicuna.gotmpl/system-user-assistant-user

@@ -0,0 +1,6 @@
+You are a helpful assistant.
+
+USER: Hello, how are you?
+ASSISTANT: I'm doing great. How can I help you today?</s>
+USER: I'd like to show off how chat templating works!
+ASSISTANT:

+ 2 - 0
template/testdata/vicuna.gotmpl/user

@@ -0,0 +1,2 @@
+USER: Hello, how are you?
+ASSISTANT:

+ 4 - 0
template/testdata/vicuna.gotmpl/user-assistant-user

@@ -0,0 +1,4 @@
+USER: Hello, how are you?
+ASSISTANT: I'm doing great. How can I help you today?</s>
+USER: I'd like to show off how chat templating works!
+ASSISTANT:

+ 9 - 0
template/testdata/zephyr.gotmpl/system-user-assistant-user

@@ -0,0 +1,9 @@
+<|system|>
+You are a helpful assistant.</s>
+<|user|>
+Hello, how are you?</s>
+<|assistant|>
+I'm doing great. How can I help you today?</s>
+<|user|>
+I'd like to show off how chat templating works!</s>
+<|assistant|>

+ 3 - 0
template/testdata/zephyr.gotmpl/user

@@ -0,0 +1,3 @@
+<|user|>
+Hello, how are you?</s>
+<|assistant|>

+ 7 - 0
template/testdata/zephyr.gotmpl/user-assistant-user

@@ -0,0 +1,7 @@
+<|user|>
+Hello, how are you?</s>
+<|assistant|>
+I'm doing great. How can I help you today?</s>
+<|user|>
+I'd like to show off how chat templating works!</s>
+<|assistant|>

+ 12 - 1
template/vicuna.gotmpl

@@ -1,3 +1,14 @@
+{{- if .Messages }}
+{{- if .System }}{{ .System }}
+
+{{ end }}
+{{- range .Messages }}
+{{- if eq .Role "user" }}USER: {{ .Content }}
+{{ else if eq .Role "assistant" }}ASSISTANT: {{ .Content }}</s>
+{{ end }}
+{{- end }}ASSISTANT:
+{{- else }}
 {{ if .System }}{{ .System }}
 {{ end }}{{ if .Prompt }}USER: {{ .Prompt }}
-{{ end }}ASSISTANT: {{ .Response }}
+{{ end }}ASSISTANT: {{ .Response }}
+{{- end }}

+ 10 - 1
template/zephyr.gotmpl

@@ -1,6 +1,15 @@
+{{- if .Messages }}
+{{- if .System }}<|system|>
+{{ .System }}</s>
+{{ end }}
+{{- range .Messages }}<|{{ .Role }}|>
+{{ .Content }}</s>
+{{ end }}<|assistant|>
+{{ else }}
 {{ if .System }}<|system|>
 {{ .System }}</s>
 {{ end }}{{ if .Prompt }}<|user|>
 {{ .Prompt }}</s>
 {{ end }}<|assistant|>
-{{ .Response }}</s>
+{{ .Response }}</s>
+{{- end }}