From 25bee71bb8077aae09eb1b91196c7d1cabd33b11 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 20 Feb 2025 15:02:18 +0100 Subject: [PATCH] feat(ui): do also filter tts and image models (#4871) Signed-off-by: Ettore Di Giacinto --- core/http/routes/ui.go | 105 +++++++++++++++++++++----------- core/http/views/chat.html | 18 ++---- core/http/views/text2image.html | 16 +++-- core/http/views/tts.html | 16 +++-- 4 files changed, 94 insertions(+), 61 deletions(-) diff --git a/core/http/routes/ui.go b/core/http/routes/ui.go index f60b3698..350d0914 100644 --- a/core/http/routes/ui.go +++ b/core/http/routes/ui.go @@ -327,23 +327,31 @@ func RegisterUIRoutes(app *fiber.App, }) app.Get("/chat/", 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) - if len(allModels) == 0 { + if len(backendConfigs)+len(modelsWithoutConfig) == 0 { // If no model is available redirect to the index which suggests how to install models return c.Redirect(utils.BaseURL(c)) } + modelThatCanBeUsed := "" + + title := "LocalAI - Chat" + + for _, b := range backendConfigs { + if b.HasUsecases(config.FLAG_CHAT) { + modelThatCanBeUsed = b.Name + title = "LocalAI - Chat with " + modelThatCanBeUsed + break + } + } summary := fiber.Map{ - "Title": "LocalAI - Chat with " + allModels[0], + "Title": title, "BaseURL": utils.BaseURL(c), - "AllModels": allModels, "ModelsWithoutConfig": modelsWithoutConfig, "ModelsConfig": backendConfigs, - "Model": allModels[0], + "Model": modelThatCanBeUsed, "Version": internal.PrintableVersion(), "IsP2PEnabled": p2p.IsP2PEnabled(), } @@ -354,7 +362,6 @@ func RegisterUIRoutes(app *fiber.App, // 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) @@ -363,7 +370,6 @@ func RegisterUIRoutes(app *fiber.App, "BaseURL": utils.BaseURL(c), "ModelsConfig": backendConfigs, "ModelsWithoutConfig": modelsWithoutConfig, - "AllModels": allModels, "Model": c.Params("model"), "Version": internal.PrintableVersion(), "IsP2PEnabled": p2p.IsP2PEnabled(), @@ -375,14 +381,16 @@ func RegisterUIRoutes(app *fiber.App, app.Get("/text2image/:model", func(c *fiber.Ctx) error { backendConfigs := cl.GetAllBackendConfigs() + modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) summary := fiber.Map{ - "Title": "LocalAI - Generate images with " + c.Params("model"), - "BaseURL": utils.BaseURL(c), - "ModelsConfig": backendConfigs, - "Model": c.Params("model"), - "Version": internal.PrintableVersion(), - "IsP2PEnabled": p2p.IsP2PEnabled(), + "Title": "LocalAI - Generate images with " + c.Params("model"), + "BaseURL": utils.BaseURL(c), + "ModelsConfig": backendConfigs, + "ModelsWithoutConfig": modelsWithoutConfig, + "Model": c.Params("model"), + "Version": internal.PrintableVersion(), + "IsP2PEnabled": p2p.IsP2PEnabled(), } // Render index @@ -390,21 +398,33 @@ func RegisterUIRoutes(app *fiber.App, }) app.Get("/text2image/", func(c *fiber.Ctx) error { - backendConfigs := cl.GetAllBackendConfigs() + modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) - if len(backendConfigs) == 0 { + if len(backendConfigs)+len(modelsWithoutConfig) == 0 { // If no model is available redirect to the index which suggests how to install models return c.Redirect(utils.BaseURL(c)) } + modelThatCanBeUsed := "" + title := "LocalAI - Generate images" + + for _, b := range backendConfigs { + if b.HasUsecases(config.FLAG_IMAGE) { + modelThatCanBeUsed = b.Name + title = "LocalAI - Generate images with " + modelThatCanBeUsed + break + } + } + summary := fiber.Map{ - "Title": "LocalAI - Generate images with " + backendConfigs[0].Name, - "BaseURL": utils.BaseURL(c), - "ModelsConfig": backendConfigs, - "Model": backendConfigs[0].Name, - "Version": internal.PrintableVersion(), - "IsP2PEnabled": p2p.IsP2PEnabled(), + "Title": title, + "BaseURL": utils.BaseURL(c), + "ModelsConfig": backendConfigs, + "ModelsWithoutConfig": modelsWithoutConfig, + "Model": modelThatCanBeUsed, + "Version": internal.PrintableVersion(), + "IsP2PEnabled": p2p.IsP2PEnabled(), } // Render index @@ -413,14 +433,16 @@ func RegisterUIRoutes(app *fiber.App, app.Get("/tts/:model", func(c *fiber.Ctx) error { backendConfigs := cl.GetAllBackendConfigs() + modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) summary := fiber.Map{ - "Title": "LocalAI - Generate images with " + c.Params("model"), - "BaseURL": utils.BaseURL(c), - "ModelsConfig": backendConfigs, - "Model": c.Params("model"), - "Version": internal.PrintableVersion(), - "IsP2PEnabled": p2p.IsP2PEnabled(), + "Title": "LocalAI - Generate images with " + c.Params("model"), + "BaseURL": utils.BaseURL(c), + "ModelsConfig": backendConfigs, + "ModelsWithoutConfig": modelsWithoutConfig, + "Model": c.Params("model"), + "Version": internal.PrintableVersion(), + "IsP2PEnabled": p2p.IsP2PEnabled(), } // Render index @@ -428,21 +450,32 @@ func RegisterUIRoutes(app *fiber.App, }) app.Get("/tts/", func(c *fiber.Ctx) error { - backendConfigs := cl.GetAllBackendConfigs() + modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY) - if len(backendConfigs) == 0 { + if len(backendConfigs)+len(modelsWithoutConfig) == 0 { // If no model is available redirect to the index which suggests how to install models return c.Redirect(utils.BaseURL(c)) } + modelThatCanBeUsed := "" + title := "LocalAI - Generate audio" + + for _, b := range backendConfigs { + if b.HasUsecases(config.FLAG_CHAT) { + modelThatCanBeUsed = b.Name + title = "LocalAI - Generate audio with " + modelThatCanBeUsed + break + } + } summary := fiber.Map{ - "Title": "LocalAI - Generate audio with " + backendConfigs[0].Name, - "BaseURL": utils.BaseURL(c), - "ModelsConfig": backendConfigs, - "Model": backendConfigs[0].Name, - "IsP2PEnabled": p2p.IsP2PEnabled(), - "Version": internal.PrintableVersion(), + "Title": title, + "BaseURL": utils.BaseURL(c), + "ModelsConfig": backendConfigs, + "ModelsWithoutConfig": modelsWithoutConfig, + "Model": modelThatCanBeUsed, + "IsP2PEnabled": p2p.IsP2PEnabled(), + "Version": internal.PrintableVersion(), } // Render index diff --git a/core/http/views/chat.html b/core/http/views/chat.html index 4f06a1a4..b3e9bd4a 100644 --- a/core/http/views/chat.html +++ b/core/http/views/chat.html @@ -44,7 +44,7 @@ SOFTWARE.
-

Chat with {{.Model}} +

Chat {{ if .Model }} with {{.Model}} {{ end }}

diff --git a/core/http/views/text2image.html b/core/http/views/text2image.html index a3a95b05..10eef2d7 100644 --- a/core/http/views/text2image.html +++ b/core/http/views/text2image.html @@ -13,7 +13,7 @@
- 🖼️ Text to Image + 🖼️ Text to Image {{ if .Model }} (using {{.Model}}) {{ end }} @@ -49,12 +49,16 @@ {{ $model:=.Model}} {{ range .ModelsConfig }} - {{ if eq .Name $model }} - - {{ else }} - - {{ end }} + {{ $cfg := . }} + {{ range .KnownUsecaseStrings }} + {{ if eq . "FLAG_IMAGE" }} + + {{ end }} + {{ end }} {{ end }} + {{ range .ModelsWithoutConfig }} + + {{end}}
diff --git a/core/http/views/tts.html b/core/http/views/tts.html index 154dad0c..d00927cf 100644 --- a/core/http/views/tts.html +++ b/core/http/views/tts.html @@ -11,7 +11,7 @@
- Text to speech/audio + Text to speech/audio {{ if .Model }} (using {{.Model}}) {{ end }} @@ -46,12 +46,16 @@ {{ $model:=.Model}} {{ range .ModelsConfig }} - {{ if eq .Name $model }} - - {{ else }} - - {{ end }} + {{ $cfg := . }} + {{ range .KnownUsecaseStrings }} + {{ if eq . "FLAG_TTS" }} + + {{ end }} + {{ end }} {{ end }} + {{ range .ModelsWithoutConfig }} + + {{end}}