mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-25 21:15:00 +00:00
feat(prepare): allow to specify additional files to download (#1526)
This commit is contained in:
parent
f068efe509
commit
522659eb59
1 changed files with 28 additions and 3 deletions
|
@ -52,6 +52,14 @@ type Config struct {
|
||||||
// CUDA
|
// CUDA
|
||||||
// Explicitly enable CUDA or not (some backends might need it)
|
// Explicitly enable CUDA or not (some backends might need it)
|
||||||
CUDA bool `yaml:"cuda"`
|
CUDA bool `yaml:"cuda"`
|
||||||
|
|
||||||
|
DownloadFiles []File `yaml:"download_files"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type File struct {
|
||||||
|
Filename string `yaml:"filename" json:"filename"`
|
||||||
|
SHA256 string `yaml:"sha256" json:"sha256"`
|
||||||
|
URI string `yaml:"uri" json:"uri"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VallE struct {
|
type VallE struct {
|
||||||
|
@ -272,10 +280,29 @@ func (cm *ConfigLoader) Preload(modelPath string) error {
|
||||||
cm.Lock()
|
cm.Lock()
|
||||||
defer cm.Unlock()
|
defer cm.Unlock()
|
||||||
|
|
||||||
|
status := func(fileName, current, total string, percent float64) {
|
||||||
|
utils.DisplayDownloadFunction(fileName, current, total, percent)
|
||||||
|
}
|
||||||
|
|
||||||
log.Info().Msgf("Preloading models from %s", modelPath)
|
log.Info().Msgf("Preloading models from %s", modelPath)
|
||||||
|
|
||||||
for i, config := range cm.configs {
|
for i, config := range cm.configs {
|
||||||
|
|
||||||
|
// Download files and verify their SHA
|
||||||
|
for _, file := range config.DownloadFiles {
|
||||||
|
log.Debug().Msgf("Checking %q exists and matches SHA", file.Filename)
|
||||||
|
|
||||||
|
if err := utils.VerifyPath(file.Filename, modelPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Create file path
|
||||||
|
filePath := filepath.Join(modelPath, file.Filename)
|
||||||
|
|
||||||
|
if err := utils.DownloadFile(file.URI, filePath, file.SHA256, status); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
modelURL := config.PredictionOptions.Model
|
modelURL := config.PredictionOptions.Model
|
||||||
modelURL = utils.ConvertURL(modelURL)
|
modelURL = utils.ConvertURL(modelURL)
|
||||||
|
|
||||||
|
@ -285,9 +312,7 @@ func (cm *ConfigLoader) Preload(modelPath string) error {
|
||||||
|
|
||||||
// check if file exists
|
// check if file exists
|
||||||
if _, err := os.Stat(filepath.Join(modelPath, md5Name)); errors.Is(err, os.ErrNotExist) {
|
if _, err := os.Stat(filepath.Join(modelPath, md5Name)); errors.Is(err, os.ErrNotExist) {
|
||||||
err := utils.DownloadFile(modelURL, filepath.Join(modelPath, md5Name), "", func(fileName, current, total string, percent float64) {
|
err := utils.DownloadFile(modelURL, filepath.Join(modelPath, md5Name), "", status)
|
||||||
utils.DisplayDownloadFunction(fileName, current, total, percent)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue