Skip to content

Commit e30fc05

Browse files
committed
feat(defaults): add defaults for Command-R models
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 6c087ae commit e30fc05

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

core/config/guesser.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,48 @@ type familyType uint8
1313

1414
const (
1515
Unknown familyType = iota
16-
LLaMa3 = iota
17-
LLama2 = iota
16+
LLaMa3
17+
LLama2
18+
CommandR
1819
)
1920

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{
2127
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|>"},
2458
},
2559
}
2660

@@ -68,10 +102,14 @@ func guessDefaultsFromFile(cfg *BackendConfig, modelPath string) {
68102
return
69103
}
70104

71-
templ, ok := defaultsTemplate[family]
105+
// identify template
106+
settings, ok := defaultsSettings[family]
72107
if ok {
73-
cfg.TemplateConfig = templ
108+
cfg.TemplateConfig = settings.TemplateConfig
74109
log.Debug().Any("family", family).Msgf("guessDefaultsFromFile: guessed template %+v", cfg.TemplateConfig)
110+
if len(cfg.StopWords) == 0 {
111+
cfg.StopWords = settings.StopWords
112+
}
75113
} else {
76114
log.Debug().Any("family", family).Msgf("guessDefaultsFromFile: no template found for family")
77115
}
@@ -81,6 +119,8 @@ func identifyFamily(f *gguf.GGUFFile) familyType {
81119
switch {
82120
case f.Architecture().Architecture == "llama" && f.Tokenizer().EOSTokenID == 128009:
83121
return LLaMa3
122+
case f.Architecture().Architecture == "command-r" && f.Tokenizer().EOSTokenID == 255001:
123+
return CommandR
84124
}
85125

86126
return Unknown

0 commit comments

Comments
 (0)