mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 14:35:00 +00:00
Feats: bruno example, gallery improvements for new scraper (#1161)
This PR bundles together two unrelated features: 1. Model Gallery improvements - specifically, the ability to follow ".ref" gallery links (which I made up for this specific application) to an actual gallery yaml file (in order to have stable URLs) and the ability to load self-contained configurations, rather than always using a base.yaml + overrides. This is groundwork for my python-based huggingface scraper. 2. A while ago I introduced some Insomnia request templates for people to use. Unfortunately, Insomnia has decided to tank their product... So I've personally switched to using [bruno](https://github.com/usebruno/bruno/). Corresponding equivalent files that I use for my testing have been added. Just open the folder from bruno and everything will work. No import process required. --------- Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
This commit is contained in:
parent
8ac7186185
commit
44a7045732
21 changed files with 383 additions and 9 deletions
|
@ -21,9 +21,31 @@ func InstallModelFromGallery(galleries []Gallery, name string, basePath string,
|
|||
applyModel := func(model *GalleryModel) error {
|
||||
name = strings.ReplaceAll(name, string(os.PathSeparator), "__")
|
||||
|
||||
config, err := GetGalleryConfigFromURL(model.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
var config Config
|
||||
|
||||
if len(model.URL) > 0 {
|
||||
var err error
|
||||
config, err = GetGalleryConfigFromURL(model.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if len(model.ConfigFile) > 0 {
|
||||
// TODO: is this worse than using the override method with a blank cfg yaml?
|
||||
reYamlConfig, err := yaml.Marshal(model.ConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
config = Config{
|
||||
ConfigFile: string(reYamlConfig),
|
||||
Description: model.Description,
|
||||
License: model.License,
|
||||
URLs: model.URLs,
|
||||
Name: model.Name,
|
||||
Files: make([]File, 0), // Real values get added below, must be blank
|
||||
// Prompt Template Skipped for now - I expect in this mode that they will be delivered as files.
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("invalid gallery model %+v", model)
|
||||
}
|
||||
|
||||
installName := model.Name
|
||||
|
@ -115,13 +137,36 @@ func AvailableGalleryModels(galleries []Gallery, basePath string) ([]*GalleryMod
|
|||
return models, nil
|
||||
}
|
||||
|
||||
func findGalleryURLFromReferenceURL(url string) (string, error) {
|
||||
var refFile string
|
||||
err := utils.GetURI(url, func(url string, d []byte) error {
|
||||
refFile = string(d)
|
||||
if len(refFile) == 0 {
|
||||
return fmt.Errorf("invalid reference file at url %s: %s", url, d)
|
||||
}
|
||||
cutPoint := strings.LastIndex(url, "/")
|
||||
refFile = url[:cutPoint+1] + refFile
|
||||
return nil
|
||||
})
|
||||
return refFile, err
|
||||
}
|
||||
|
||||
func getGalleryModels(gallery Gallery, basePath string) ([]*GalleryModel, error) {
|
||||
var models []*GalleryModel = []*GalleryModel{}
|
||||
|
||||
if strings.HasSuffix(gallery.URL, ".ref") {
|
||||
var err error
|
||||
gallery.URL, err = findGalleryURLFromReferenceURL(gallery.URL)
|
||||
if err != nil {
|
||||
return models, err
|
||||
}
|
||||
}
|
||||
|
||||
err := utils.GetURI(gallery.URL, func(url string, d []byte) error {
|
||||
return yaml.Unmarshal(d, &models)
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
return models, err
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ func GetGalleryConfigFromURL(url string) (Config, error) {
|
|||
return yaml.Unmarshal(d, &config)
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Msgf("GetGalleryConfigFromURL error for url %s\n%s", url, err.Error())
|
||||
return config, err
|
||||
}
|
||||
return config, nil
|
||||
|
|
|
@ -11,8 +11,9 @@ type GalleryModel struct {
|
|||
URLs []string `json:"urls,omitempty" yaml:"urls,omitempty"`
|
||||
Icon string `json:"icon,omitempty" yaml:"icon,omitempty"`
|
||||
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
|
||||
|
||||
// Overrides are used to override the configuration of the model
|
||||
// config_file is read in the situation where URL is blank - and therefore this is a base config.
|
||||
ConfigFile map[string]interface{} `json:"config_file,omitempty" yaml:"config_file,omitempty"`
|
||||
// Overrides are used to override the configuration of the model located at URL
|
||||
Overrides map[string]interface{} `json:"overrides,omitempty" yaml:"overrides,omitempty"`
|
||||
// AdditionalFiles are used to add additional files to the model
|
||||
AdditionalFiles []File `json:"files,omitempty" yaml:"files,omitempty"`
|
||||
|
@ -21,7 +22,3 @@ type GalleryModel struct {
|
|||
// Installed is used to indicate if the model is installed or not
|
||||
Installed bool `json:"installed,omitempty" yaml:"installed,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
githubURI = "github:"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue