LocalAI/core/dependencies_manager/manager.go
Ettore Di Giacinto a36b721ca6
fix: be consistent in downloading files, check for scanner errors (#3108)
* fix(downloader): be consistent in downloading files

This PR puts some order in the downloader such as functions are re-used
across several places.

This fixes an issue with having uri's inside the model YAML file, it
would resolve to MD5 rather then using the filename

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(scanner): do raise error only if unsafeFiles are found

Fixes: https://github.com/mudler/LocalAI/issues/3114

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2024-08-02 20:06:25 +02:00

48 lines
952 B
Go

package main
import (
"fmt"
"os"
"path/filepath"
"github.com/mudler/LocalAI/pkg/downloader"
"github.com/mudler/LocalAI/pkg/utils"
"gopkg.in/yaml.v3"
)
type Asset struct {
FileName string `yaml:"filename"`
URL string `yaml:"url"`
SHA string `yaml:"sha"`
}
func main() {
// read the YAML file which contains a list of assets
// and download them in the asset path
assets := []Asset{}
assetFile := os.Args[1]
destPath := os.Args[2]
// read the YAML file
f, err := os.ReadFile(assetFile)
if err != nil {
panic(err)
}
// unmarshal the YAML data into a struct
if err := yaml.Unmarshal(f, &assets); err != nil {
panic(err)
}
// download the assets
for _, asset := range assets {
uri := downloader.URI(asset.URL)
if err := uri.DownloadFile(filepath.Join(destPath, asset.FileName), asset.SHA, 1, 1, utils.DisplayDownloadFunction); err != nil {
panic(err)
}
}
fmt.Println("Finished downloading assets")
}