@@ -13,14 +13,48 @@ type familyType uint8
13
13
14
14
const (
15
15
Unknown familyType = iota
16
- LLaMa3 = iota
17
- LLama2 = iota
16
+ LLaMa3
17
+ LLama2
18
+ CommandR
18
19
)
19
20
20
- var defaultsTemplate map [familyType ]TemplateConfig = map [familyType ]TemplateConfig {
21
+ type settingsConfig struct {
22
+ StopWords []string
23
+ TemplateConfig TemplateConfig
24
+ }
25
+
26
+ var defaultsSettings map [familyType ]settingsConfig = map [familyType ]settingsConfig {
21
27
LLaMa3 : {
22
- Chat : "<|begin_of_text|>{{.Input }}\n <|start_header_id|>assistant<|end_header_id|>" ,
23
- ChatMessage : "<|start_header_id|>{{ .RoleName }}<|end_header_id|>\n \n {{.Content }}<|eot_id|>" ,
28
+ StopWords : []string {"<|eot_id|>" },
29
+ TemplateConfig : TemplateConfig {
30
+ Chat : "<|begin_of_text|>{{.Input }}\n <|start_header_id|>assistant<|end_header_id|>" ,
31
+ ChatMessage : "<|start_header_id|>{{ .RoleName }}<|end_header_id|>\n \n {{.Content }}<|eot_id|>" ,
32
+ },
33
+ },
34
+ CommandR : {
35
+ TemplateConfig : TemplateConfig {
36
+ Chat : "{{.Input -}}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>" ,
37
+ Functions : `<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
38
+ You are a function calling AI model, you can call the following functions:
39
+ ## Available Tools
40
+ {{range .Functions}}
41
+ - {"type": "function", "function": {"name": "{{.Name}}", "description": "{{.Description}}", "parameters": {{toJson .Parameters}} }}
42
+ {{end}}
43
+ When using a tool, reply with JSON, for instance {"name": "tool_name", "arguments": {"param1": "value1", "param2": "value2"}}
44
+ <|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{{.Input -}}` ,
45
+ ChatMessage : `{{if eq .RoleName "user" -}}
46
+ <|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{.Content}}<|END_OF_TURN_TOKEN|>
47
+ {{- else if eq .RoleName "system" -}}
48
+ <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{.Content}}<|END_OF_TURN_TOKEN|>
49
+ {{- else if eq .RoleName "assistant" -}}
50
+ <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{{.Content}}<|END_OF_TURN_TOKEN|>
51
+ {{- else if eq .RoleName "tool" -}}
52
+ <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{.Content}}<|END_OF_TURN_TOKEN|>
53
+ {{- else if .FunctionCall -}}
54
+ <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{{toJson .FunctionCall}}}<|END_OF_TURN_TOKEN|>
55
+ {{- end -}}` ,
56
+ },
57
+ StopWords : []string {"<|END_OF_TURN_TOKEN|>" },
24
58
},
25
59
}
26
60
@@ -68,10 +102,14 @@ func guessDefaultsFromFile(cfg *BackendConfig, modelPath string) {
68
102
return
69
103
}
70
104
71
- templ , ok := defaultsTemplate [family ]
105
+ // identify template
106
+ settings , ok := defaultsSettings [family ]
72
107
if ok {
73
- cfg .TemplateConfig = templ
108
+ cfg .TemplateConfig = settings . TemplateConfig
74
109
log .Debug ().Any ("family" , family ).Msgf ("guessDefaultsFromFile: guessed template %+v" , cfg .TemplateConfig )
110
+ if len (cfg .StopWords ) == 0 {
111
+ cfg .StopWords = settings .StopWords
112
+ }
75
113
} else {
76
114
log .Debug ().Any ("family" , family ).Msgf ("guessDefaultsFromFile: no template found for family" )
77
115
}
@@ -81,6 +119,8 @@ func identifyFamily(f *gguf.GGUFFile) familyType {
81
119
switch {
82
120
case f .Architecture ().Architecture == "llama" && f .Tokenizer ().EOSTokenID == 128009 :
83
121
return LLaMa3
122
+ case f .Architecture ().Architecture == "command-r" && f .Tokenizer ().EOSTokenID == 255001 :
123
+ return CommandR
84
124
}
85
125
86
126
return Unknown
0 commit comments