MCPcopy
hub / github.com/mudler/LocalAI / Run

Method Run

core/cli/models.go:74–144  ·  view source on GitHub ↗
(ctx *cliContext.Context)

Source from the content-addressed store, hash-verified

72}
73
74func (mi *ModelsInstall) Run(ctx *cliContext.Context) error {
75 systemState, err := system.GetSystemState(
76 system.WithModelPath(mi.ModelsPath),
77 system.WithBackendPath(mi.BackendsPath),
78 )
79 if err != nil {
80 return err
81 }
82
83 galleryService := galleryop.NewGalleryService(&config.ApplicationConfig{
84 SystemState: systemState,
85 }, model.NewModelLoader(systemState))
86 err = galleryService.Start(context.Background(), config.NewModelConfigLoader(mi.ModelsPath), systemState)
87 if err != nil {
88 return err
89 }
90
91 var galleries []config.Gallery
92 if err := json.Unmarshal([]byte(mi.Galleries), &galleries); err != nil {
93 xlog.Error("unable to load galleries", "error", err)
94 }
95
96 var backendGalleries []config.Gallery
97 if err := json.Unmarshal([]byte(mi.BackendGalleries), &backendGalleries); err != nil {
98 xlog.Error("unable to load backend galleries", "error", err)
99 }
100
101 for _, modelName := range mi.ModelArgs {
102
103 progressBar := progressbar.NewOptions(
104 1000,
105 progressbar.OptionSetDescription(fmt.Sprintf("downloading model %s", modelName)),
106 progressbar.OptionShowBytes(false),
107 progressbar.OptionClearOnFinish(),
108 )
109 progressCallback := func(fileName string, current string, total string, percentage float64) {
110 v := int(percentage * 10)
111 err := progressBar.Set(v)
112 if err != nil {
113 xlog.Error("error while updating progress bar", "error", err, "filename", fileName, "value", v)
114 }
115 }
116 //startup.InstallModels()
117 models, err := gallery.AvailableGalleryModels(galleries, systemState)
118 if err != nil {
119 return err
120 }
121
122 modelURI := downloader.URI(modelName)
123
124 if !modelURI.LooksLikeOCI() {
125 model := gallery.FindGalleryElement(models, modelName)
126 if model == nil {
127 xlog.Error("model not found", "model", modelName)
128 return err
129 }
130
131 err = gallery.SafetyScanGalleryModel(model)

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
GetSystemStateFunction · 0.92
WithModelPathFunction · 0.92
WithBackendPathFunction · 0.92
NewGalleryServiceFunction · 0.92
NewModelLoaderFunction · 0.92
NewModelConfigLoaderFunction · 0.92
AvailableGalleryModelsFunction · 0.92
URITypeAlias · 0.92
FindGalleryElementFunction · 0.92
SafetyScanGalleryModelFunction · 0.92
InstallModelsFunction · 0.92

Tested by

no test coverage detected