feat(ui): show only text models in the chat interface (#4869)

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2025-02-19 17:34:30 +01:00 committed by GitHub
parent 08311f275a
commit ea0c9f1168
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 34 deletions

View file

@ -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 { app.Get("/talk/", func(c *fiber.Ctx) error {
backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED) 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 { 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 // If no model is available redirect to the index which suggests how to install models
return c.Redirect(utils.BaseURL(c)) return c.Redirect(utils.BaseURL(c))
} }
summary := fiber.Map{ summary := fiber.Map{
"Title": "LocalAI - Chat with " + backendConfigs[0], "Title": "LocalAI - Chat with " + allModels[0],
"BaseURL": utils.BaseURL(c), "BaseURL": utils.BaseURL(c),
"ModelsConfig": backendConfigs, "AllModels": allModels,
"Model": backendConfigs[0], "ModelsWithoutConfig": modelsWithoutConfig,
"Version": internal.PrintableVersion(), "ModelsConfig": backendConfigs,
"IsP2PEnabled": p2p.IsP2PEnabled(), "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 // Render index

View file

@ -100,14 +100,25 @@ SOFTWARE.
<option value="" disabled class="text-gray-400" >Select a model</option> <option value="" disabled class="text-gray-400" >Select a model</option>
{{ $model:=.Model}} {{ $model:=.Model}}
{{ range .ModelsConfig }} {{ range .ModelsConfig }}
{{ if eq . $model }} {{ $cfg := . }}
<option value="chat/{{.}}" selected class="bg-gray-700 text-white">{{.}}</option> {{ if eq .Name $model }}
{{ else }} <option value="chat/{{.Name}}" selected class="bg-gray-700 text-white">{{.Name}}</option>
<option value="chat/{{.}}" class="bg-gray-700 text-white">{{.}}</option> {{ else }}
{{ end }} {{ range .KnownUsecaseStrings }}
{{ if eq . "FLAG_CHAT" }}
<option value="chat/{{$cfg.Name}}" class="bg-gray-700 text-white">{{$cfg.Name}}</option>
{{ end }}
{{ end }}
{{ end }}
{{ end }} {{ end }}
{{ range .ModelsWithoutConfig }}
{{ if eq . $model }}
<option value="chat/{{.}}" selected class="bg-gray-700 text-white">{{.}}</option>
{{ else }}
<option value="chat/{{.}}" class="bg-gray-700 text-white">{{.}}</option>
{{ end }}
{{end}}
</select> </select>
</div> </div>
</div> </div>

View file

@ -50,6 +50,7 @@
{{$galleryConfig:=.GalleryConfig}} {{$galleryConfig:=.GalleryConfig}}
{{$noicon:="https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg"}} {{$noicon:="https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg"}}
{{ range .ModelsConfig }} {{ range .ModelsConfig }}
{{ $backendCfg := . }}
{{ $cfg:= index $galleryConfig .Name}} {{ $cfg:= index $galleryConfig .Name}}
<tr class="bg-gray-800 border-b border-gray-700"> <tr class="bg-gray-800 border-b border-gray-700">
<td class="px-4 py-3"> <td class="px-4 py-3">
@ -69,13 +70,13 @@
<p class="font-bold text-white flex items-center">{{.Name}} <a href="browse?term={{.Name}}" class="ml-2 text-blue-400 hover:text-blue-600"><i class="fas fa-search"></i></a></p> <p class="font-bold text-white flex items-center">{{.Name}} <a href="browse?term={{.Name}}" class="ml-2 text-blue-400 hover:text-blue-600"><i class="fas fa-search"></i></a></p>
{{ range .KnownUsecaseStrings }} {{ range .KnownUsecaseStrings }}
{{ if eq . "FLAG_CHAT" }} {{ if eq . "FLAG_CHAT" }}
<a href="chat/{{$cfg.Name}}" class="ml-2 bg-blue-500 text-white py-1 px-3 rounded-lg shadow transition duration-300 ease-in-out hover:bg-blue-700 hover:shadow-lg"><i class="fas fa-comments pr-1"></i>Chat</a> <a href="chat/{{$backendCfg.Name}}" class="ml-2 bg-blue-500 text-white py-1 px-3 rounded-lg shadow transition duration-300 ease-in-out hover:bg-blue-700 hover:shadow-lg"><i class="fas fa-comments pr-1"></i>Chat</a>
{{ end }} {{ end }}
{{ if eq . "FLAG_IMAGE" }} {{ if eq . "FLAG_IMAGE" }}
<a href="text2image/{{$cfg.Name}}" class="ml-2 bg-green-500 text-white py-1 px-3 rounded-lg shadow transition duration-300 ease-in-out hover:bg-green-700 hover:shadow-lg"><i class="fas fa-image pr-1"></i>Image</a> <a href="text2image/{{$backendCfg.Name}}" class="ml-2 bg-green-500 text-white py-1 px-3 rounded-lg shadow transition duration-300 ease-in-out hover:bg-green-700 hover:shadow-lg"><i class="fas fa-image pr-1"></i>Image</a>
{{ end }} {{ end }}
{{ if eq . "FLAG_TTS" }} {{ if eq . "FLAG_TTS" }}
<a href="tts/{{$cfg.Name}}" class="ml-2 bg-purple-500 text-white py-1 px-3 rounded-lg shadow transition duration-300 ease-in-out hover:bg-purple-700 hover:shadow-lg"><i class="fas fa-microphone pr-1"></i>TTS</a> <a href="tts/{{$backendCfg.Name}}" class="ml-2 bg-purple-500 text-white py-1 px-3 rounded-lg shadow transition duration-300 ease-in-out hover:bg-purple-700 hover:shadow-lg"><i class="fas fa-microphone pr-1"></i>TTS</a>
{{ end }} {{ end }}
{{ end }} {{ end }}
</td> </td>