|
5 | 5 | "fmt" |
6 | 6 | "os" |
7 | 7 | "path/filepath" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/go-skynet/LocalAI/embedded" |
10 | 11 | "github.com/go-skynet/LocalAI/pkg/downloader" |
@@ -52,6 +53,28 @@ func InstallModels(galleries []gallery.Gallery, modelLibraryURL string, modelPat |
52 | 53 | log.Error().Err(e).Str("filepath", modelDefinitionFilePath).Msg("error writing model definition") |
53 | 54 | err = errors.Join(err, e) |
54 | 55 | } |
| 56 | + case downloader.LooksLikeOCI(url): |
| 57 | + log.Debug().Msgf("[startup] resolved OCI model to download: %s", url) |
| 58 | + |
| 59 | + // convert OCI image name to a file name. |
| 60 | + ociName := strings.TrimPrefix(url, downloader.OCIPrefix) |
| 61 | + ociName = strings.TrimPrefix(ociName, downloader.OllamaPrefix) |
| 62 | + ociName = strings.ReplaceAll(ociName, "/", "__") |
| 63 | + ociName = strings.ReplaceAll(ociName, ":", "__") |
| 64 | + |
| 65 | + // check if file exists |
| 66 | + if _, e := os.Stat(filepath.Join(modelPath, ociName)); errors.Is(e, os.ErrNotExist) { |
| 67 | + modelDefinitionFilePath := filepath.Join(modelPath, ociName) |
| 68 | + e := downloader.DownloadFile(url, modelDefinitionFilePath, "", 0, 0, func(fileName, current, total string, percent float64) { |
| 69 | + utils.DisplayDownloadFunction(fileName, current, total, percent) |
| 70 | + }) |
| 71 | + if e != nil { |
| 72 | + log.Error().Err(e).Str("url", url).Str("filepath", modelDefinitionFilePath).Msg("error downloading model") |
| 73 | + err = errors.Join(err, e) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + log.Info().Msgf("[startup] installed model from OCI repository: %s", ociName) |
55 | 78 | case downloader.LooksLikeURL(url): |
56 | 79 | log.Debug().Msgf("[startup] resolved model to download: %s", url) |
57 | 80 |
|
|
0 commit comments