From 1027c487a62752fbc9508b1c7173275d39c9e63c Mon Sep 17 00:00:00 2001 From: "LocalAI [bot]" <139863280+localai-bot@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:18:42 +0100 Subject: [PATCH] fix: reload model after editing YAML config (issue #8647) (#8652) fix: reload model configuration after editing (issue #8647) - Add *model.ModelLoader parameter to EditModelEndpoint - Call ml.ShutdownModel() after saving config to unload the running model - Model will be reloaded on next inference request with new settings (e.g., context_size) - Update route registration to pass ml to EditModelEndpoint Signed-off-by: localai-bot Co-authored-by: localai-bot --- core/http/endpoints/localai/edit_model.go | 13 +++++++++++-- core/http/routes/localai.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/http/endpoints/localai/edit_model.go b/core/http/endpoints/localai/edit_model.go index 4a44610a3..0d033283c 100644 --- a/core/http/endpoints/localai/edit_model.go +++ b/core/http/endpoints/localai/edit_model.go @@ -10,6 +10,7 @@ import ( "github.com/mudler/LocalAI/core/config" httpUtils "github.com/mudler/LocalAI/core/http/middleware" "github.com/mudler/LocalAI/internal" + "github.com/mudler/LocalAI/pkg/model" "github.com/mudler/LocalAI/pkg/utils" "gopkg.in/yaml.v3" @@ -78,7 +79,7 @@ func GetEditModelPage(cl *config.ModelConfigLoader, appConfig *config.Applicatio } // EditModelEndpoint handles updating existing model configurations -func EditModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig) echo.HandlerFunc { +func EditModelEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) echo.HandlerFunc { return func(c echo.Context) error { modelName := c.Param("name") if modelName == "" { @@ -174,6 +175,14 @@ func EditModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applicati return c.JSON(http.StatusInternalServerError, response) } + // Shutdown the running model to apply new configuration (e.g., context_size) + // The model will be reloaded on the next inference request + if err := ml.ShutdownModel(modelName); err != nil { + // Log the error but don't fail the request - the config was saved successfully + // The model can still be manually reloaded or restarted + fmt.Printf("Warning: Failed to shutdown model '%s': %v\n", modelName, err) + } + // Preload the model if err := cl.Preload(appConfig.SystemState.Model.ModelsPath); err != nil { response := ModelResponse{ @@ -186,7 +195,7 @@ func EditModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applicati // Return success response response := ModelResponse{ Success: true, - Message: fmt.Sprintf("Model '%s' updated successfully", modelName), + Message: fmt.Sprintf("Model '%s' updated successfully. Model has been reloaded with new configuration.", modelName), Filename: configPath, Config: req, } diff --git a/core/http/routes/localai.go b/core/http/routes/localai.go index 7b3248084..4c8d57751 100644 --- a/core/http/routes/localai.go +++ b/core/http/routes/localai.go @@ -66,7 +66,7 @@ func RegisterLocalAIRoutes(router *echo.Echo, router.POST("/models/import-uri", localai.ImportModelURIEndpoint(cl, appConfig, galleryService, opcache)) // Custom model edit endpoint - router.POST("/models/edit/:name", localai.EditModelEndpoint(cl, appConfig)) + router.POST("/models/edit/:name", localai.EditModelEndpoint(cl, ml, appConfig)) // Reload models endpoint router.POST("/models/reload", localai.ReloadModelsEndpoint(cl, appConfig))