mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
feat: allow to override model config (#323)
This commit is contained in:
parent
7bc08797f9
commit
05a3d569b0
12 changed files with 269 additions and 64 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
. "github.com/go-skynet/LocalAI/pkg/gallery"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var _ = Describe("Model test", func() {
|
||||
|
@ -18,14 +19,25 @@ var _ = Describe("Model test", func() {
|
|||
c, err := ReadConfigFile(filepath.Join(os.Getenv("FIXTURES"), "gallery_simple.yaml"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = Apply(tempdir, "", c)
|
||||
err = Apply(tempdir, "", c, map[string]interface{}{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
for _, f := range []string{"cerebras", "cerebras-completion.tmpl", "cerebras-chat.tmpl", "cerebras.yaml"} {
|
||||
_, err = os.Stat(filepath.Join(tempdir, f))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
content := map[string]interface{}{}
|
||||
|
||||
dat, err := os.ReadFile(filepath.Join(tempdir, "cerebras.yaml"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = yaml.Unmarshal(dat, content)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(content["context_size"]).To(Equal(1024))
|
||||
})
|
||||
|
||||
It("renames model correctly", func() {
|
||||
tempdir, err := os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -33,7 +45,7 @@ var _ = Describe("Model test", func() {
|
|||
c, err := ReadConfigFile(filepath.Join(os.Getenv("FIXTURES"), "gallery_simple.yaml"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = Apply(tempdir, "foo", c)
|
||||
err = Apply(tempdir, "foo", c, map[string]interface{}{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
for _, f := range []string{"cerebras", "cerebras-completion.tmpl", "cerebras-chat.tmpl", "foo.yaml"} {
|
||||
|
@ -41,6 +53,33 @@ var _ = Describe("Model test", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
})
|
||||
|
||||
It("overrides parameters", func() {
|
||||
tempdir, err := os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer os.RemoveAll(tempdir)
|
||||
c, err := ReadConfigFile(filepath.Join(os.Getenv("FIXTURES"), "gallery_simple.yaml"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = Apply(tempdir, "foo", c, map[string]interface{}{"backend": "foo"})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
for _, f := range []string{"cerebras", "cerebras-completion.tmpl", "cerebras-chat.tmpl", "foo.yaml"} {
|
||||
_, err = os.Stat(filepath.Join(tempdir, f))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
content := map[string]interface{}{}
|
||||
|
||||
dat, err := os.ReadFile(filepath.Join(tempdir, "foo.yaml"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = yaml.Unmarshal(dat, content)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(content["backend"]).To(Equal("foo"))
|
||||
})
|
||||
|
||||
It("catches path traversals", func() {
|
||||
tempdir, err := os.MkdirTemp("", "test")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -48,7 +87,7 @@ var _ = Describe("Model test", func() {
|
|||
c, err := ReadConfigFile(filepath.Join(os.Getenv("FIXTURES"), "gallery_simple.yaml"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = Apply(tempdir, "../../../foo", c)
|
||||
err = Apply(tempdir, "../../../foo", c, map[string]interface{}{})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue