mirror of
https://github.com/mudler/LocalAI
synced 2026-04-21 13:27:21 +00:00
fix(config): ignore yaml backup files in model loader (#9443)
Only load files whose real extension is .yaml or .yml so backup files like model.yaml.bak do not override active configs. Add a regression test covering plain and timestamped backup files. Assisted-by: Codex:gpt-5.4 docker Signed-off-by: leinasi2014 <leinasi2014@gmail.com>
This commit is contained in:
parent
c66c41e8d7
commit
486b5e25a3
2 changed files with 49 additions and 3 deletions
|
|
@ -373,9 +373,9 @@ func (bcl *ModelConfigLoader) LoadModelConfigsFromPath(path string, opts ...Conf
|
||||||
files = append(files, info)
|
files = append(files, info)
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// Skip templates, YAML and .keep files
|
// Only load real YAML config files and ignore dotfiles or backup variants
|
||||||
if !strings.Contains(file.Name(), ".yaml") && !strings.Contains(file.Name(), ".yml") ||
|
ext := strings.ToLower(filepath.Ext(file.Name()))
|
||||||
strings.HasPrefix(file.Name(), ".") {
|
if (ext != ".yaml" && ext != ".yml") || strings.HasPrefix(file.Name(), ".") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
@ -109,5 +110,50 @@ options:
|
||||||
Expect(testModel.Options).To(ContainElements("foo", "bar", "baz"))
|
Expect(testModel.Options).To(ContainElements("foo", "bar", "baz"))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("Only loads files ending with yaml or yml", func() {
|
||||||
|
tmpdir, err := os.MkdirTemp("", "model-config-loader")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
err = os.WriteFile(filepath.Join(tmpdir, "foo.yaml"), []byte(
|
||||||
|
`name: "foo-model"
|
||||||
|
description: "formal config"
|
||||||
|
backend: "llama-cpp"
|
||||||
|
parameters:
|
||||||
|
model: "foo.gguf"
|
||||||
|
`), 0644)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
err = os.WriteFile(filepath.Join(tmpdir, "foo.yaml.bak"), []byte(
|
||||||
|
`name: "foo-model"
|
||||||
|
description: "backup config"
|
||||||
|
backend: "llama-cpp"
|
||||||
|
parameters:
|
||||||
|
model: "foo-backup.gguf"
|
||||||
|
`), 0644)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
err = os.WriteFile(filepath.Join(tmpdir, "foo.yaml.bak.123"), []byte(
|
||||||
|
`name: "foo-backup-only"
|
||||||
|
description: "timestamped backup config"
|
||||||
|
backend: "llama-cpp"
|
||||||
|
parameters:
|
||||||
|
model: "foo-timestamped.gguf"
|
||||||
|
`), 0644)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
bcl := NewModelConfigLoader(tmpdir)
|
||||||
|
err = bcl.LoadModelConfigsFromPath(tmpdir)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
configs := bcl.GetAllModelsConfigs()
|
||||||
|
Expect(configs).To(HaveLen(1))
|
||||||
|
Expect(configs[0].Name).To(Equal("foo-model"))
|
||||||
|
Expect(configs[0].Description).To(Equal("formal config"))
|
||||||
|
|
||||||
|
_, exists := bcl.GetModelConfig("foo-backup-only")
|
||||||
|
Expect(exists).To(BeFalse())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue