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

Function TogglePinnedModelEndpoint

core/http/endpoints/localai/pin_model.go:26–44  ·  view source on GitHub ↗

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())

Source from the content-addressed store, hash-verified

24// @Failure 500 {object} ModelResponse
25// @Router /api/models/toggle-pinned/{name}/{action} [put]
26func 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}

Callers 1

RegisterLocalAIRoutesFunction · 0.92

Calls 8

TogglePinnedMethod · 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