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

Function ToggleStateModelEndpoint

core/http/endpoints/localai/toggle_model.go:28–54  ·  view source on GitHub ↗

ToggleModelEndpoint handles enabling or disabling a model from being loaded on demand. When disabled, the model remains in the collection but will not be loaded when requested. @Summary Toggle model enabled/disabled status @Description Enable or disable a model from being loaded on demand. Di

(cl *config.ModelConfigLoader, ml *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig)

Source from the content-addressed store, hash-verified

26// @Failure 500 {object} ModelResponse
27// @Router /api/models/{name}/{action} [put]
28func ToggleStateModelEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig) echo.HandlerFunc {
29 svc := modeladmin.NewConfigService(cl, appConfig)
30 return func(c echo.Context) error {
31 modelName := c.Param("name")
32 if decoded, err := url.PathUnescape(modelName); err == nil {
33 modelName = decoded
34 }
35 action := modeladmin.Action(c.Param("action"))
36 result, err := svc.ToggleState(c.Request().Context(), modelName, action, ml)
37 if err != nil {
38 return c.JSON(httpStatusForModelAdminError(err), ModelResponse{Success: false, Error: err.Error()})
39 }
40
41 // Enabling/disabling rewrites the config on disk and reloads only the
42 // local loader; tell peers to refresh so the model's availability is
43 // consistent across replicas. No-op in standalone mode.
44 if gs != nil {
45 gs.BroadcastModelsChanged(modelName, "install")
46 }
47
48 msg := fmt.Sprintf("Model '%s' has been %sd successfully.", modelName, action)
49 if action == modeladmin.ActionDisable {
50 msg += " The model will not be loaded on demand until re-enabled."
51 }
52 return c.JSON(http.StatusOK, ModelResponse{Success: true, Message: msg, Filename: result.Filename})
53 }
54}

Callers 1

RegisterLocalAIRoutesFunction · 0.92

Calls 9

ToggleStateMethod · 0.95
NewConfigServiceFunction · 0.92
ActionTypeAlias · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
RequestMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected