GetEditModelPage renders the edit model page with current configuration
(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig)
| 18 | |
| 19 | // GetEditModelPage renders the edit model page with current configuration |
| 20 | func GetEditModelPage(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig) echo.HandlerFunc { |
| 21 | svc := modeladmin.NewConfigService(cl, appConfig) |
| 22 | return func(c echo.Context) error { |
| 23 | modelName := c.Param("name") |
| 24 | if decoded, err := url.PathUnescape(modelName); err == nil { |
| 25 | modelName = decoded |
| 26 | } |
| 27 | view, err := svc.GetConfig(c.Request().Context(), modelName) |
| 28 | if err != nil { |
| 29 | return c.JSON(httpStatusForModelAdminError(err), ModelResponse{Success: false, Error: err.Error()}) |
| 30 | } |
| 31 | // Render the edit page with the current configuration. Re-fetch the |
| 32 | // in-memory config from the loader for the template — the on-disk YAML |
| 33 | // view from svc doesn't carry the loader's parsed struct fields. |
| 34 | modelConfig, _ := cl.GetModelConfig(modelName) |
| 35 | templateData := struct { |
| 36 | Title string |
| 37 | ModelName string |
| 38 | Config *config.ModelConfig |
| 39 | ConfigJSON string |
| 40 | ConfigYAML string |
| 41 | BaseURL string |
| 42 | Version string |
| 43 | DisableRuntimeSettings bool |
| 44 | }{ |
| 45 | Title: "LocalAI - Edit Model " + modelName, |
| 46 | ModelName: modelName, |
| 47 | Config: &modelConfig, |
| 48 | ConfigYAML: view.YAML, |
| 49 | BaseURL: httpUtils.BaseURL(c), |
| 50 | Version: internal.PrintableVersion(), |
| 51 | DisableRuntimeSettings: appConfig.DisableRuntimeSettings, |
| 52 | } |
| 53 | |
| 54 | return c.Render(http.StatusOK, "views/model-editor", templateData) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // EditModelEndpoint handles updating existing model configurations |
| 59 | func EditModelEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig) echo.HandlerFunc { |
no test coverage detected