Skip to content

Commit 59af0e7

Browse files
authored
feat(ui): allow to select between all the available models in the chat (#2657)
feat(ui): let the chat to select from all the detected models Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 5d83c8d commit 59af0e7

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

core/http/routes/ui.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func RegisterUIRoutes(app *fiber.App,
2626
appConfig *config.ApplicationConfig,
2727
galleryService *services.GalleryService,
2828
auth func(*fiber.Ctx) error) {
29+
tmpLMS := services.NewListModelsService(ml, cl, appConfig) // TODO: once createApplication() is fully in use, reference the central instance.
2930

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

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

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

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

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

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

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

272-
backendConfigs := cl.GetAllBackendConfigs()
273+
backendConfigs, _ := tmpLMS.ListModels("", true)
273274

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

279280
summary := fiber.Map{
280-
"Title": "LocalAI - Chat with " + backendConfigs[0].Name,
281+
"Title": "LocalAI - Chat with " + backendConfigs[0].ID,
281282
"ModelsConfig": backendConfigs,
282-
"Model": backendConfigs[0].Name,
283+
"Model": backendConfigs[0].ID,
283284
"Version": internal.PrintableVersion(),
284285
}
285286

core/http/views/chat.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ <h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat wit
100100
<option value="" disabled class="text-gray-400" >Select a model</option>
101101
{{ $model:=.Model}}
102102
{{ range .ModelsConfig }}
103-
{{ if eq .Name $model }}
104-
<option value="/chat/{{.Name}}" selected class="bg-gray-700 text-white">{{.Name}}</option>
103+
{{ if eq .ID $model }}
104+
<option value="/chat/{{.ID}}" selected class="bg-gray-700 text-white">{{.ID}}</option>
105105
{{ else }}
106-
<option value="/chat/{{.Name}}" class="bg-gray-700 text-white">{{.Name}}</option>
106+
<option value="/chat/{{.ID}}" class="bg-gray-700 text-white">{{.ID}}</option>
107107
{{ end }}
108108
{{ end }}
109109
</select>

core/http/views/talk.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<option value="" disabled class="text-gray-400" >Select a model</option>
6363

6464
{{ range .ModelsConfig }}
65-
<option value="{{.Name}}" class="bg-gray-700 text-white">{{.Name}}</option>
65+
<option value="{{.ID}}" class="bg-gray-700 text-white">{{.ID}}</option>
6666
{{ end }}
6767
</select>
6868
</div>

0 commit comments

Comments
 (0)