PatchConfigEndpoint handles PATCH requests to partially update a model config using nested JSON merge. @Summary Partially update a model configuration @Description Deep-merges the JSON patch body into the existing model config @Tags config @Accept json @Produce json @Param name path string true "Mod
(cl *config.ModelConfigLoader, _ *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig)
| 156 | // @Success 200 {object} map[string]any "success message" |
| 157 | // @Router /api/models/config-json/{name} [patch] |
| 158 | func PatchConfigEndpoint(cl *config.ModelConfigLoader, _ *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig) echo.HandlerFunc { |
| 159 | svc := modeladmin.NewConfigService(cl, appConfig) |
| 160 | return func(c echo.Context) error { |
| 161 | modelName := c.Param("name") |
| 162 | if decoded, err := url.PathUnescape(modelName); err == nil { |
| 163 | modelName = decoded |
| 164 | } |
| 165 | patchBody, err := io.ReadAll(c.Request().Body) |
| 166 | if err != nil || len(patchBody) == 0 { |
| 167 | return c.JSON(http.StatusBadRequest, map[string]any{"error": "request body is empty or unreadable"}) |
| 168 | } |
| 169 | var patchMap map[string]any |
| 170 | if err := json.Unmarshal(patchBody, &patchMap); err != nil { |
| 171 | return c.JSON(http.StatusBadRequest, map[string]any{"error": "invalid JSON: " + err.Error()}) |
| 172 | } |
| 173 | if _, err := svc.PatchConfig(c.Request().Context(), modelName, patchMap); err != nil { |
| 174 | return c.JSON(httpStatusForModelAdminError(err), map[string]any{"error": err.Error()}) |
| 175 | } |
| 176 | |
| 177 | // Patch rewrites the config on disk and reloads only the local loader; |
| 178 | // tell peers to refresh so the change is consistent across replicas. |
| 179 | // No-op in standalone mode. |
| 180 | if gs != nil { |
| 181 | gs.BroadcastModelsChanged(modelName, "install") |
| 182 | } |
| 183 | |
| 184 | return c.JSON(http.StatusOK, map[string]any{ |
| 185 | "success": true, |
| 186 | "message": fmt.Sprintf("Model '%s' updated successfully", modelName), |
| 187 | }) |
| 188 | } |
| 189 | } |
no test coverage detected