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

Function EditModelEndpoint

core/http/endpoints/localai/edit_model.go:59–96  ·  view source on GitHub ↗

EditModelEndpoint handles updating existing model configurations

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

Source from the content-addressed store, hash-verified

57
58// EditModelEndpoint handles updating existing model configurations
59func EditModelEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig) echo.HandlerFunc {
60 svc := modeladmin.NewConfigService(cl, appConfig)
61 return func(c echo.Context) error {
62 modelName := c.Param("name")
63 if decoded, err := url.PathUnescape(modelName); err == nil {
64 modelName = decoded
65 }
66 body, err := io.ReadAll(c.Request().Body)
67 if err != nil {
68 return c.JSON(http.StatusBadRequest, ModelResponse{Success: false, Error: "Failed to read request body: " + err.Error()})
69 }
70 result, err := svc.EditYAML(c.Request().Context(), modelName, body, ml)
71 if err != nil {
72 return c.JSON(httpStatusForModelAdminError(err), ModelResponse{Success: false, Error: err.Error()})
73 }
74
75 // Tell peer replicas to refresh their in-memory config: this endpoint
76 // only reloaded the local loader. A rename is a delete of the old name
77 // plus an install of the new one. No-op in standalone mode.
78 if gs != nil {
79 if result.Renamed {
80 gs.BroadcastModelsChanged(result.OldName, "delete")
81 }
82 gs.BroadcastModelsChanged(result.NewName, "install")
83 }
84
85 msg := fmt.Sprintf("Model '%s' updated successfully. Model has been reloaded with new configuration.", result.NewName)
86 if result.Renamed {
87 msg = fmt.Sprintf("Model '%s' renamed to '%s' and updated successfully.", result.OldName, result.NewName)
88 }
89 return c.JSON(http.StatusOK, ModelResponse{
90 Success: true,
91 Message: msg,
92 Filename: result.Filename,
93 Config: result.Config,
94 })
95 }
96}
97
98// httpStatusForModelAdminError maps the typed errors from modeladmin to
99// the HTTP status codes the existing endpoints used to return — keeps the

Callers 2

RegisterLocalAIRoutesFunction · 0.92
edit_model_test.goFile · 0.85

Calls 8

EditYAMLMethod · 0.95
NewConfigServiceFunction · 0.92
JSONMethod · 0.80
RequestMethod · 0.65
ContextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected