Skip to content

Commit 077ddbf

Browse files
OliverOliver
authored andcommitted
feat(conf): refactor preset.go and add load-on-startup=true
1 parent 459d1cd commit 077ddbf

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

conf/preset.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,51 @@ version = 1
4444
info := cfg.getInfo()
4545
for _, model := range slices.Sorted(maps.Keys(info)) {
4646
mi := info[model]
47-
genModel(out, model, mi.Path, mi.Flags)
48-
out.WriteString("# size = " + strconv.FormatInt(mi.Size, 10))
49-
if mi.Flags != "" {
50-
out.WriteString("\n# args = " + mi.Flags)
51-
}
52-
if mi.Origin != "" {
53-
out.WriteString("\n# args origin = " + mi.Origin)
54-
}
55-
if mi.Issue != "" {
56-
out.WriteString("\n# issue = " + mi.Issue)
57-
}
58-
genModel(out, model+PLUS_A, mi.Path, cfg.Llama.Goinfer+" "+mi.Flags)
47+
cfg.genModel(out, model, mi, false)
48+
genComment(out, mi)
49+
cfg.genModel(out, model, mi, true)
5950
}
6051

6152
return out.Bytes()
6253
}
6354

6455
// Add the model settings within the llama-swap configuration.
65-
func genModel(out *bytes.Buffer, name, path, flags string) {
56+
func genComment(out *bytes.Buffer, mi *ModelInfo) {
57+
out.WriteString("# size = " + strconv.FormatInt(mi.Size, 10))
58+
if mi.Flags != "" {
59+
out.WriteString("\n" + "# args = " + mi.Flags)
60+
}
61+
if mi.Origin != "" {
62+
out.WriteString("\n" + "# args origin = " + mi.Origin)
63+
}
64+
if mi.Issue != "" {
65+
out.WriteString("\n" + "# issue = " + mi.Issue)
66+
}
67+
}
68+
69+
// Add the model settings within the llama-swap configuration.
70+
func (cfg *Cfg) genModel(out *bytes.Buffer, model string, mi *ModelInfo, as bool) {
71+
if as {
72+
model += PLUS_A
73+
}
74+
6675
out.WriteString(`
67-
[` + name + `]
68-
model = ` + path)
76+
[` + model + `]
77+
model = ` + mi.Path)
78+
79+
if model == cfg.DefaultModel {
80+
out.WriteString("\n" + "load-on-startup = true")
81+
}
6982

7083
var val string
7184
firstLoop := true
72-
for arg := range strings.FieldsSeq(flags) {
85+
if as {
86+
for arg := range strings.FieldsSeq(cfg.Llama.Goinfer) {
87+
val = genParam(out, val, arg, firstLoop)
88+
firstLoop = false
89+
}
90+
}
91+
for arg := range strings.FieldsSeq(mi.Flags) {
7392
val = genParam(out, val, arg, firstLoop)
7493
firstLoop = false
7594
}

0 commit comments

Comments
 (0)