Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions core/config/model_config_filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package config_test

import (
. "github.com/mudler/LocalAI/core/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("BuildNameFilterFn", func() {
It("returns a pass-all filter when the filter string is empty", func() {
fn, err := BuildNameFilterFn("")
Expect(err).ToNot(HaveOccurred())
Expect(fn("any-name", nil)).To(BeTrue())
Expect(fn("another-model", &ModelConfig{Name: "another-model"})).To(BeTrue())
})

It("returns an error for an invalid regex", func() {
fn, err := BuildNameFilterFn("[invalid-regex")
Expect(err).To(HaveOccurred())
Expect(fn).To(BeNil())
})

It("matches only models whose name satisfies the regex", func() {
fn, err := BuildNameFilterFn("llama")
Expect(err).ToNot(HaveOccurred())

Expect(fn("", &ModelConfig{Name: "llama-7b"})).To(BeTrue())
Expect(fn("", &ModelConfig{Name: "my-llama-model"})).To(BeTrue())
Expect(fn("", &ModelConfig{Name: "gpt-4"})).To(BeFalse())
})
})