Skip to content

Commit fe47de8

Browse files
committed
UI
1 parent eb6dd33 commit fe47de8

24 files changed

+1150
-441
lines changed

core/gallery/backend_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ func (m *GalleryBackend) GetName() string {
2525
func (m *GalleryBackend) GetGallery() config.Gallery {
2626
return m.Gallery
2727
}
28+
29+
func (m *GalleryBackend) GetDescription() string {
30+
return m.Description
31+
}
32+
33+
func (m *GalleryBackend) GetTags() []string {
34+
return m.Tags
35+
}

core/gallery/backends_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var _ = Describe("Gallery Backends", func() {
2424
galleries = []config.Gallery{
2525
{
2626
Name: "test-gallery",
27-
URL: "https://raw.githubusercontent.com/mudler/LocalAI/refs/heads/master/gallery/index.yaml",
27+
URL: "https://gist.githubusercontent.com/mudler/71d5376bc2aa168873fa519fa9f4bd56/raw/0557f9c640c159fa8e4eab29e8d98df6a3d6e80f/backend-gallery.yaml",
2828
},
2929
}
3030
})
@@ -40,8 +40,11 @@ var _ = Describe("Gallery Backends", func() {
4040
Expect(err.Error()).To(ContainSubstring("no backend found with name"))
4141
})
4242

43-
// Note: Full installation test would require mocking the OCI client
44-
// which is beyond the scope of this basic test setup
43+
It("should install backend from gallery", func() {
44+
err := InstallBackendFromGallery(galleries, "test-backend", tempDir, nil)
45+
Expect(err).ToNot(HaveOccurred())
46+
Expect(filepath.Join(tempDir, "test-backend", "run.sh")).To(BeARegularFile())
47+
})
4548
})
4649

4750
Describe("InstallBackend", func() {

core/gallery/gallery.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,49 @@ type GalleryElement interface {
4646
SetGallery(gallery config.Gallery)
4747
SetInstalled(installed bool)
4848
GetName() string
49+
GetDescription() string
50+
GetTags() []string
4951
GetGallery() config.Gallery
5052
}
5153

54+
type GalleryElements[T GalleryElement] []T
55+
56+
func (gm GalleryElements[T]) Search(term string) GalleryElements[T] {
57+
var filteredModels GalleryElements[T]
58+
59+
for _, m := range gm {
60+
if strings.Contains(m.GetName(), term) ||
61+
strings.Contains(m.GetDescription(), term) ||
62+
strings.Contains(m.GetGallery().Name, term) ||
63+
strings.Contains(strings.Join(m.GetTags(), ","), term) {
64+
filteredModels = append(filteredModels, m)
65+
}
66+
}
67+
return filteredModels
68+
}
69+
70+
func (gm GalleryElements[T]) FindByName(name string) T {
71+
for _, m := range gm {
72+
if strings.EqualFold(m.GetName(), name) {
73+
return m
74+
}
75+
}
76+
var zero T
77+
return zero
78+
}
79+
80+
func (gm GalleryElements[T]) Paginate(pageNum int, itemsNum int) GalleryElements[T] {
81+
start := (pageNum - 1) * itemsNum
82+
end := start + itemsNum
83+
if start > len(gm) {
84+
start = len(gm)
85+
}
86+
if end > len(gm) {
87+
end = len(gm)
88+
}
89+
return gm[start:end]
90+
}
91+
5292
func FindGalleryElement[T GalleryElement](models []T, name string, basePath string) T {
5393
var model T
5494
name = strings.ReplaceAll(name, string(os.PathSeparator), "__")
@@ -76,7 +116,7 @@ func FindGalleryElement[T GalleryElement](models []T, name string, basePath stri
76116
// List available models
77117
// Models galleries are a list of yaml files that are hosted on a remote server (for example github).
78118
// Each yaml file contains a list of models that can be downloaded and optionally overrides to define a new model setting.
79-
func AvailableGalleryModels(galleries []config.Gallery, basePath string) (GalleryModels, error) {
119+
func AvailableGalleryModels(galleries []config.Gallery, basePath string) (GalleryElements[*GalleryModel], error) {
80120
var models []*GalleryModel
81121

82122
// Get models from galleries
@@ -92,7 +132,7 @@ func AvailableGalleryModels(galleries []config.Gallery, basePath string) (Galler
92132
}
93133

94134
// List available backends
95-
func AvailableBackends(galleries []config.Gallery, basePath string) (GalleryBackends, error) {
135+
func AvailableBackends(galleries []config.Gallery, basePath string) (GalleryElements[*GalleryBackend], error) {
96136
var models []*GalleryBackend
97137

98138
// Get models from galleries
@@ -149,9 +189,13 @@ func getGalleryElements[T GalleryElement](gallery config.Gallery, basePath strin
149189
model.SetGallery(gallery)
150190
// we check if the model was already installed by checking if the config file exists
151191
// TODO: (what to do if the model doesn't install a config file?)
192+
// TODO: This is sub-optimal now that the gallery handles both backends and models - we need to abstract this away
152193
if _, err := os.Stat(filepath.Join(basePath, fmt.Sprintf("%s.yaml", model.GetName()))); err == nil {
153194
model.SetInstalled(true)
154195
}
196+
if _, err := os.Stat(filepath.Join(basePath, model.GetName())); err == nil {
197+
model.SetInstalled(true)
198+
}
155199
}
156200
return models, nil
157201
}

core/gallery/models_types.go

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gallery
22

33
import (
44
"fmt"
5-
"strings"
65

76
"github.com/mudler/LocalAI/core/config"
87
)
@@ -38,39 +37,10 @@ func (m GalleryModel) ID() string {
3837
return fmt.Sprintf("%s@%s", m.Gallery.Name, m.Name)
3938
}
4039

41-
type GalleryModels []*GalleryModel
42-
43-
func (gm GalleryModels) Search(term string) GalleryModels {
44-
var filteredModels GalleryModels
45-
46-
for _, m := range gm {
47-
if strings.Contains(m.Name, term) ||
48-
strings.Contains(m.Description, term) ||
49-
strings.Contains(m.Gallery.Name, term) ||
50-
strings.Contains(strings.Join(m.Tags, ","), term) {
51-
filteredModels = append(filteredModels, m)
52-
}
53-
}
54-
return filteredModels
55-
}
56-
57-
func (gm GalleryModels) FindByName(name string) *GalleryModel {
58-
for _, m := range gm {
59-
if strings.EqualFold(m.Name, name) {
60-
return m
61-
}
62-
}
63-
return nil
40+
func (m *GalleryModel) GetTags() []string {
41+
return m.Tags
6442
}
6543

66-
func (gm GalleryModels) Paginate(pageNum int, itemsNum int) GalleryModels {
67-
start := (pageNum - 1) * itemsNum
68-
end := start + itemsNum
69-
if start > len(gm) {
70-
start = len(gm)
71-
}
72-
if end > len(gm) {
73-
end = len(gm)
74-
}
75-
return gm[start:end]
44+
func (m *GalleryModel) GetDescription() string {
45+
return m.Description
7646
}

core/gallery/op.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)