|
package gallery |
|
|
|
import ( |
|
"fmt" |
|
"strings" |
|
|
|
"github.com/mudler/LocalAI/core/config" |
|
) |
|
|
|
|
|
|
|
|
|
type GalleryModel struct { |
|
URL string `json:"url,omitempty" yaml:"url,omitempty"` |
|
Name string `json:"name,omitempty" yaml:"name,omitempty"` |
|
Description string `json:"description,omitempty" yaml:"description,omitempty"` |
|
License string `json:"license,omitempty" yaml:"license,omitempty"` |
|
URLs []string `json:"urls,omitempty" yaml:"urls,omitempty"` |
|
Icon string `json:"icon,omitempty" yaml:"icon,omitempty"` |
|
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` |
|
|
|
ConfigFile map[string]interface{} `json:"config_file,omitempty" yaml:"config_file,omitempty"` |
|
|
|
Overrides map[string]interface{} `json:"overrides,omitempty" yaml:"overrides,omitempty"` |
|
|
|
AdditionalFiles []File `json:"files,omitempty" yaml:"files,omitempty"` |
|
|
|
Gallery config.Gallery `json:"gallery,omitempty" yaml:"gallery,omitempty"` |
|
|
|
Installed bool `json:"installed,omitempty" yaml:"installed,omitempty"` |
|
} |
|
|
|
func (m GalleryModel) ID() string { |
|
return fmt.Sprintf("%s@%s", m.Gallery.Name, m.Name) |
|
} |
|
|
|
type GalleryModels []*GalleryModel |
|
|
|
func (gm GalleryModels) Search(term string) GalleryModels { |
|
var filteredModels GalleryModels |
|
|
|
for _, m := range gm { |
|
if strings.Contains(m.Name, term) || |
|
strings.Contains(m.Description, term) || |
|
strings.Contains(m.Gallery.Name, term) || |
|
strings.Contains(strings.Join(m.Tags, ","), term) { |
|
filteredModels = append(filteredModels, m) |
|
} |
|
} |
|
return filteredModels |
|
} |
|
|
|
func (gm GalleryModels) FindByName(name string) *GalleryModel { |
|
for _, m := range gm { |
|
if strings.EqualFold(m.Name, name) { |
|
return m |
|
} |
|
} |
|
return nil |
|
} |
|
|