mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 14:35:00 +00:00
feat(gallery): show available models in website, allow local-ai models install
to install from galleries (#2555)
* WIP Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * gen a static page instead (we force DNS redirects to it) Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(gallery): install models from CLI, unify install Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Uniform graphic of model page Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Makefile: update targets Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Slightly enhance gallery view Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
f8382adbf7
commit
882556d4db
6 changed files with 383 additions and 55 deletions
|
@ -20,6 +20,7 @@ type Gallery struct {
|
|||
|
||||
// Installs a model from the gallery (galleryname@modelname)
|
||||
func InstallModelFromGallery(galleries []Gallery, name string, basePath string, req GalleryModel, downloadStatus func(string, string, string, float64)) error {
|
||||
|
||||
applyModel := func(model *GalleryModel) error {
|
||||
name = strings.ReplaceAll(name, string(os.PathSeparator), "__")
|
||||
|
||||
|
@ -78,50 +79,44 @@ func InstallModelFromGallery(galleries []Gallery, name string, basePath string,
|
|||
return err
|
||||
}
|
||||
|
||||
model, err := FindGallery(models, name)
|
||||
if err != nil {
|
||||
var err2 error
|
||||
model, err2 = FindGallery(models, strings.ToLower(name))
|
||||
if err2 != nil {
|
||||
return err
|
||||
}
|
||||
model := FindModel(models, name, basePath)
|
||||
if model == nil {
|
||||
return fmt.Errorf("no model found with name %q", name)
|
||||
}
|
||||
|
||||
return applyModel(model)
|
||||
}
|
||||
|
||||
func FindGallery(models []*GalleryModel, name string) (*GalleryModel, error) {
|
||||
// os.PathSeparator is not allowed in model names. Replace them with "__" to avoid conflicts with file paths.
|
||||
func FindModel(models []*GalleryModel, name string, basePath string) *GalleryModel {
|
||||
var model *GalleryModel
|
||||
name = strings.ReplaceAll(name, string(os.PathSeparator), "__")
|
||||
|
||||
for _, model := range models {
|
||||
if name == fmt.Sprintf("%s@%s", model.Gallery.Name, model.Name) {
|
||||
return model, nil
|
||||
if !strings.Contains(name, "@") {
|
||||
for _, m := range models {
|
||||
if strings.EqualFold(m.Name, name) {
|
||||
model = m
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if model == nil {
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
for _, m := range models {
|
||||
if strings.EqualFold(name, fmt.Sprintf("%s@%s", m.Gallery.Name, m.Name)) {
|
||||
model = m
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("no gallery found with name %q", name)
|
||||
|
||||
return model
|
||||
}
|
||||
|
||||
// InstallModelFromGalleryByName loads a model from the gallery by specifying only the name (first match wins)
|
||||
// InstallModelFromGalleryByName is planned for deprecation
|
||||
func InstallModelFromGalleryByName(galleries []Gallery, name string, basePath string, req GalleryModel, downloadStatus func(string, string, string, float64)) error {
|
||||
models, err := AvailableGalleryModels(galleries, basePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name = strings.ReplaceAll(name, string(os.PathSeparator), "__")
|
||||
var model *GalleryModel
|
||||
for _, m := range models {
|
||||
if name == m.Name || m.Name == strings.ToLower(name) {
|
||||
model = m
|
||||
}
|
||||
}
|
||||
|
||||
if model == nil {
|
||||
return fmt.Errorf("no model found with name %q", name)
|
||||
}
|
||||
|
||||
return InstallModelFromGallery(galleries, fmt.Sprintf("%s@%s", model.Gallery.Name, model.Name), basePath, req, downloadStatus)
|
||||
return InstallModelFromGallery(galleries, name, basePath, req, downloadStatus)
|
||||
}
|
||||
|
||||
// List available models
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue