TogglePinnedModelEndpoint handles pinning or unpinning a model. Pinned models are excluded from idle unloading, LRU eviction, and memory-pressure eviction. @Summary Toggle model pinned status @Description Pin or unpin a model. Pinned models stay loaded and are excluded from automatic eviction
(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig, syncPinnedFn func())
| 24 | // @Failure 500 {object} ModelResponse |
| 25 | // @Router /api/models/toggle-pinned/{name}/{action} [put] |
| 26 | func TogglePinnedModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig, syncPinnedFn func()) echo.HandlerFunc { |
| 27 | svc := modeladmin.NewConfigService(cl, appConfig) |
| 28 | return func(c echo.Context) error { |
| 29 | modelName := c.Param("name") |
| 30 | if decoded, err := url.PathUnescape(modelName); err == nil { |
| 31 | modelName = decoded |
| 32 | } |
| 33 | action := modeladmin.Action(c.Param("action")) |
| 34 | result, err := svc.TogglePinned(c.Request().Context(), modelName, action, syncPinnedFn) |
| 35 | if err != nil { |
| 36 | return c.JSON(httpStatusForModelAdminError(err), ModelResponse{Success: false, Error: err.Error()}) |
| 37 | } |
| 38 | msg := fmt.Sprintf("Model '%s' has been %sned successfully.", modelName, action) |
| 39 | if action == modeladmin.ActionPin { |
| 40 | msg += " The model will be excluded from automatic eviction." |
| 41 | } |
| 42 | return c.JSON(http.StatusOK, ModelResponse{Success: true, Message: msg, Filename: result.Filename}) |
| 43 | } |
| 44 | } |
no test coverage detected