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)
| 26 | // @Failure 500 {object} ModelResponse |
| 27 | // @Router /api/models/{name}/{action} [put] |
| 28 | func 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 | } |
no test coverage detected