11package startup
22
33import (
4+ "errors"
5+ "os"
6+ "path/filepath"
7+
48 "github.com/go-skynet/LocalAI/core/services"
59 "github.com/go-skynet/LocalAI/internal"
610 "github.com/go-skynet/LocalAI/pkg/assets"
711 "github.com/go-skynet/LocalAI/pkg/model"
812 "github.com/go-skynet/LocalAI/pkg/schema"
13+ "github.com/go-skynet/LocalAI/pkg/utils"
914 "github.com/rs/zerolog"
1015 "github.com/rs/zerolog/log"
1116)
@@ -23,6 +28,27 @@ func Startup(opts ...schema.AppOption) (*services.ConfigLoader, *model.ModelLoad
2328 log .Info ().Msgf ("Starting LocalAI using %d threads, with models path: %s" , options .Threads , options .ModelPath )
2429 log .Info ().Msgf ("LocalAI version: %s" , internal .PrintableVersion ())
2530
31+ modelPath := options .ModelPath
32+ if len (options .ModelsURL ) > 0 {
33+ for _ , url := range options .ModelsURL {
34+ url = utils .ModelShortURL (url )
35+ if utils .LooksLikeURL (url ) {
36+ // md5 of model name
37+ md5Name := utils .MD5 (url )
38+
39+ // check if file exists
40+ if _ , err := os .Stat (filepath .Join (modelPath , md5Name )); errors .Is (err , os .ErrNotExist ) {
41+ err := utils .DownloadFile (url , filepath .Join (modelPath , md5Name )+ ".yaml" , "" , func (fileName , current , total string , percent float64 ) {
42+ utils .DisplayDownloadFunction (fileName , current , total , percent )
43+ })
44+ if err != nil {
45+ log .Error ().Msgf ("error loading model: %s" , err .Error ())
46+ }
47+ }
48+ }
49+ }
50+ }
51+
2652 cl := services .NewConfigLoader ()
2753 if err := cl .LoadConfigs (options .ModelPath ); err != nil {
2854 log .Error ().Msgf ("error loading config files: %s" , err .Error ())
0 commit comments