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

Function GetEditModelPage

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

GetEditModelPage renders the edit model page with current configuration

(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig)

Source from the content-addressed store, hash-verified

18
19// GetEditModelPage renders the edit model page with current configuration
20func 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
59func EditModelEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, gs *galleryop.GalleryService, appConfig *config.ApplicationConfig) echo.HandlerFunc {

Callers 2

RegisterLocalAIRoutesFunction · 0.92
edit_model_test.goFile · 0.85

Calls 11

GetConfigMethod · 0.95
NewConfigServiceFunction · 0.92
PrintableVersionFunction · 0.92
JSONMethod · 0.80
BaseURLMethod · 0.80
ContextMethod · 0.65
RequestMethod · 0.65
GetModelConfigMethod · 0.65
ErrorMethod · 0.45
RenderMethod · 0.45

Tested by

no test coverage detected