diff --git a/core/gallery/gallery.go b/core/gallery/gallery.go index e746f71a3..5986bd46a 100644 --- a/core/gallery/gallery.go +++ b/core/gallery/gallery.go @@ -6,10 +6,12 @@ import ( "path/filepath" "strings" + "github.com/lithammer/fuzzysearch/fuzzy" "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/pkg/downloader" "github.com/mudler/LocalAI/pkg/system" "github.com/rs/zerolog/log" + "gopkg.in/yaml.v2" ) @@ -58,9 +60,9 @@ func (gm GalleryElements[T]) Search(term string) GalleryElements[T] { var filteredModels GalleryElements[T] for _, m := range gm { - if strings.Contains(m.GetName(), term) || - strings.Contains(m.GetDescription(), term) || - strings.Contains(m.GetGallery().Name, term) || + if fuzzy.Match(term, m.GetName()) || + fuzzy.Match(term, m.GetDescription()) || + fuzzy.Match(term, m.GetGallery().Name) || strings.Contains(strings.Join(m.GetTags(), ","), term) { filteredModels = append(filteredModels, m) } diff --git a/go.mod b/go.mod index 49c73a079..161609f1e 100644 --- a/go.mod +++ b/go.mod @@ -99,6 +99,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect github.com/libp2p/go-yamux/v5 v5.0.1 // indirect + github.com/lithammer/fuzzysearch v1.1.8 // indirect github.com/magiconair/properties v1.8.10 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/go-archive v0.1.0 // indirect diff --git a/go.sum b/go.sum index 6f4c291bd..36a66508d 100644 --- a/go.sum +++ b/go.sum @@ -431,6 +431,8 @@ github.com/libp2p/go-yamux/v5 v5.0.1 h1:f0WoX/bEF2E8SbE4c/k1Mo+/9z0O4oC/hWEA+nfY github.com/libp2p/go-yamux/v5 v5.0.1/go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU= github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q= github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs= +github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= +github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lufia/plan9stats v0.0.0-20240819163618-b1d8f4d146e7 h1:5RK988zAqB3/AN3opGfRpoQgAVqr6/A5+qRTi67VUZY=