From ea0c9f11681c4b86d07b2199e0d89a53a6566b26 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 19 Feb 2025 17:34:30 +0100 Subject: [PATCH] feat(ui): show only text models in the chat interface (#4869) Signed-off-by: Ettore Di Giacinto --- core/http/routes/ui.go | 58 ++++++++++++++++++++++---------------- core/http/views/chat.html | 23 +++++++++++---- core/http/views/index.html | 7 +++-- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/core/http/routes/ui.go b/core/http/routes/ui.go index 92d20544..f60b3698 100644 --- a/core/http/routes/ui.go +++ b/core/http/routes/ui.go @@ -305,23 +305,6 @@ func RegisterUIRoutes(app *fiber.App, }) } - // Show the Chat page - app.Get("/chat/:model", func(c *fiber.Ctx) error { - backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED) - - summary := fiber.Map{ - "Title": "LocalAI - Chat with " + c.Params("model"), - "BaseURL": utils.BaseURL(c), - "ModelsConfig": backendConfigs, - "Model": c.Params("model"), - "Version": internal.PrintableVersion(), - "IsP2PEnabled": p2p.IsP2PEnabled(), - } - - // Render index - return c.Render("views/chat", summary) - }) - app.Get("/talk/", func(c *fiber.Ctx) error { backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED) @@ -345,20 +328,45 @@ func RegisterUIRoutes(app *fiber.App, app.Get("/chat/", func(c *fiber.Ctx) error { - backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED) + allModels, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED) + backendConfigs := cl.GetAllBackendConfigs() + modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) - if len(backendConfigs) == 0 { + if len(allModels) == 0 { // If no model is available redirect to the index which suggests how to install models return c.Redirect(utils.BaseURL(c)) } summary := fiber.Map{ - "Title": "LocalAI - Chat with " + backendConfigs[0], - "BaseURL": utils.BaseURL(c), - "ModelsConfig": backendConfigs, - "Model": backendConfigs[0], - "Version": internal.PrintableVersion(), - "IsP2PEnabled": p2p.IsP2PEnabled(), + "Title": "LocalAI - Chat with " + allModels[0], + "BaseURL": utils.BaseURL(c), + "AllModels": allModels, + "ModelsWithoutConfig": modelsWithoutConfig, + "ModelsConfig": backendConfigs, + "Model": allModels[0], + "Version": internal.PrintableVersion(), + "IsP2PEnabled": p2p.IsP2PEnabled(), + } + + // Render index + return c.Render("views/chat", summary) + }) + + // Show the Chat page + app.Get("/chat/:model", func(c *fiber.Ctx) error { + allModels, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED) + backendConfigs := cl.GetAllBackendConfigs() + modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) + + summary := fiber.Map{ + "Title": "LocalAI - Chat with " + c.Params("model"), + "BaseURL": utils.BaseURL(c), + "ModelsConfig": backendConfigs, + "ModelsWithoutConfig": modelsWithoutConfig, + "AllModels": allModels, + "Model": c.Params("model"), + "Version": internal.PrintableVersion(), + "IsP2PEnabled": p2p.IsP2PEnabled(), } // Render index diff --git a/core/http/views/chat.html b/core/http/views/chat.html index 627aff8a..4f06a1a4 100644 --- a/core/http/views/chat.html +++ b/core/http/views/chat.html @@ -100,14 +100,25 @@ SOFTWARE. {{ $model:=.Model}} {{ range .ModelsConfig }} - {{ if eq . $model }} - - {{ else }} - - {{ end }} + {{ $cfg := . }} + {{ if eq .Name $model }} + + {{ else }} + {{ range .KnownUsecaseStrings }} + {{ if eq . "FLAG_CHAT" }} + + {{ end }} + {{ end }} + {{ end }} {{ end }} + {{ range .ModelsWithoutConfig }} + {{ if eq . $model }} + + {{ else }} + + {{ end }} + {{end}} - diff --git a/core/http/views/index.html b/core/http/views/index.html index 143a7b36..b9fd7074 100644 --- a/core/http/views/index.html +++ b/core/http/views/index.html @@ -50,6 +50,7 @@ {{$galleryConfig:=.GalleryConfig}} {{$noicon:="https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg"}} {{ range .ModelsConfig }} + {{ $backendCfg := . }} {{ $cfg:= index $galleryConfig .Name}} @@ -69,13 +70,13 @@

{{.Name}}

{{ range .KnownUsecaseStrings }} {{ if eq . "FLAG_CHAT" }} - Chat + Chat {{ end }} {{ if eq . "FLAG_IMAGE" }} - Image + Image {{ end }} {{ if eq . "FLAG_TTS" }} - TTS + TTS {{ end }} {{ end }}