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

Method Run

core/cli/backends.go:138–209  ·  view source on GitHub ↗
(ctx *cliContext.Context)

Source from the content-addressed store, hash-verified

136}
137
138func (bu *BackendsUpgrade) Run(ctx *cliContext.Context) error {
139 var galleries []config.Gallery
140 if err := json.Unmarshal([]byte(bu.BackendGalleries), &galleries); err != nil {
141 xlog.Error("unable to load galleries", "error", err)
142 }
143
144 systemState, err := system.GetSystemState(
145 system.WithBackendSystemPath(bu.BackendsSystemPath),
146 system.WithBackendPath(bu.BackendsPath),
147 )
148 if err != nil {
149 return err
150 }
151
152 upgrades, err := gallery.CheckBackendUpgrades(context.Background(), galleries, systemState)
153 if err != nil {
154 return fmt.Errorf("failed to check for upgrades: %w", err)
155 }
156
157 if len(upgrades) == 0 {
158 fmt.Println("All backends are up to date.")
159 return nil
160 }
161
162 // Filter to specified backends if args given
163 toUpgrade := upgrades
164 if len(bu.BackendArgs) > 0 {
165 toUpgrade = make(map[string]gallery.UpgradeInfo)
166 for _, name := range bu.BackendArgs {
167 if info, ok := upgrades[name]; ok {
168 toUpgrade[name] = info
169 } else {
170 fmt.Printf("Backend %s: no upgrade available\n", name)
171 }
172 }
173 }
174
175 if len(toUpgrade) == 0 {
176 fmt.Println("No upgrades to apply.")
177 return nil
178 }
179
180 modelLoader := model.NewModelLoader(systemState)
181 for name, info := range toUpgrade {
182 versionStr := ""
183 if info.AvailableVersion != "" {
184 versionStr = " to v" + info.AvailableVersion
185 }
186 fmt.Printf("Upgrading %s%s...\n", name, versionStr)
187
188 progressBar := progressbar.NewOptions(
189 1000,
190 progressbar.OptionSetDescription(fmt.Sprintf("downloading %s", name)),
191 progressbar.OptionShowBytes(false),
192 progressbar.OptionClearOnFinish(),
193 )
194 progressCallback := func(fileName string, current string, total string, percentage float64) {
195 v := int(percentage * 10)

Callers

nothing calls this directly

Calls 8

GetSystemStateFunction · 0.92
WithBackendSystemPathFunction · 0.92
WithBackendPathFunction · 0.92
CheckBackendUpgradesFunction · 0.92
NewModelLoaderFunction · 0.92
UpgradeBackendFunction · 0.92
SetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected