Skip to content

Commit

Permalink
feat(ui): allow to select between all the available models in the chat (
Browse files Browse the repository at this point in the history
#2657)

feat(ui): let the chat to select from all the detected models

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
  • Loading branch information
mudler authored Jun 25, 2024
1 parent 5d83c8d commit 59af0e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions core/http/routes/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func RegisterUIRoutes(app *fiber.App,
appConfig *config.ApplicationConfig,
galleryService *services.GalleryService,
auth func(*fiber.Ctx) error) {
tmpLMS := services.NewListModelsService(ml, cl, appConfig) // TODO: once createApplication() is fully in use, reference the central instance.

// keeps the state of models that are being installed from the UI
var processingModels = xsync.NewSyncedMap[string, string]()
Expand Down Expand Up @@ -235,7 +236,7 @@ func RegisterUIRoutes(app *fiber.App,

// Show the Chat page
app.Get("/chat/:model", auth, func(c *fiber.Ctx) error {
backendConfigs := cl.GetAllBackendConfigs()
backendConfigs, _ := tmpLMS.ListModels("", true)

summary := fiber.Map{
"Title": "LocalAI - Chat with " + c.Params("model"),
Expand All @@ -249,7 +250,7 @@ func RegisterUIRoutes(app *fiber.App,
})

app.Get("/talk/", auth, func(c *fiber.Ctx) error {
backendConfigs := cl.GetAllBackendConfigs()
backendConfigs, _ := tmpLMS.ListModels("", true)

if len(backendConfigs) == 0 {
// If no model is available redirect to the index which suggests how to install models
Expand All @@ -259,7 +260,7 @@ func RegisterUIRoutes(app *fiber.App,
summary := fiber.Map{
"Title": "LocalAI - Talk",
"ModelsConfig": backendConfigs,
"Model": backendConfigs[0].Name,
"Model": backendConfigs[0].ID,
"Version": internal.PrintableVersion(),
}

Expand All @@ -269,17 +270,17 @@ func RegisterUIRoutes(app *fiber.App,

app.Get("/chat/", auth, func(c *fiber.Ctx) error {

backendConfigs := cl.GetAllBackendConfigs()
backendConfigs, _ := tmpLMS.ListModels("", true)

if len(backendConfigs) == 0 {
// If no model is available redirect to the index which suggests how to install models
return c.Redirect("/")
}

summary := fiber.Map{
"Title": "LocalAI - Chat with " + backendConfigs[0].Name,
"Title": "LocalAI - Chat with " + backendConfigs[0].ID,
"ModelsConfig": backendConfigs,
"Model": backendConfigs[0].Name,
"Model": backendConfigs[0].ID,
"Version": internal.PrintableVersion(),
}

Expand Down
6 changes: 3 additions & 3 deletions core/http/views/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ <h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat wit
<option value="" disabled class="text-gray-400" >Select a model</option>
{{ $model:=.Model}}
{{ range .ModelsConfig }}
{{ if eq .Name $model }}
<option value="/chat/{{.Name}}" selected class="bg-gray-700 text-white">{{.Name}}</option>
{{ if eq .ID $model }}
<option value="/chat/{{.ID}}" selected class="bg-gray-700 text-white">{{.ID}}</option>
{{ else }}
<option value="/chat/{{.Name}}" class="bg-gray-700 text-white">{{.Name}}</option>
<option value="/chat/{{.ID}}" class="bg-gray-700 text-white">{{.ID}}</option>
{{ end }}
{{ end }}
</select>
Expand Down
2 changes: 1 addition & 1 deletion core/http/views/talk.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<option value="" disabled class="text-gray-400" >Select a model</option>

{{ range .ModelsConfig }}
<option value="{{.Name}}" class="bg-gray-700 text-white">{{.Name}}</option>
<option value="{{.ID}}" class="bg-gray-700 text-white">{{.ID}}</option>
{{ end }}
</select>
</div>
Expand Down

0 comments on commit 59af0e7

Please sign in to comment.