Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): allow to select between all the available models in the chat #2657

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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