Skip to content

Commit 25bee71

Browse files
authored
feat(ui): do also filter tts and image models (#4871)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent b993780 commit 25bee71

File tree

4 files changed

+94
-61
lines changed

4 files changed

+94
-61
lines changed

core/http/routes/ui.go

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -327,23 +327,31 @@ func RegisterUIRoutes(app *fiber.App,
327327
})
328328

329329
app.Get("/chat/", func(c *fiber.Ctx) error {
330-
331-
allModels, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
332330
backendConfigs := cl.GetAllBackendConfigs()
333331
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
334332

335-
if len(allModels) == 0 {
333+
if len(backendConfigs)+len(modelsWithoutConfig) == 0 {
336334
// If no model is available redirect to the index which suggests how to install models
337335
return c.Redirect(utils.BaseURL(c))
338336
}
337+
modelThatCanBeUsed := ""
338+
339+
title := "LocalAI - Chat"
340+
341+
for _, b := range backendConfigs {
342+
if b.HasUsecases(config.FLAG_CHAT) {
343+
modelThatCanBeUsed = b.Name
344+
title = "LocalAI - Chat with " + modelThatCanBeUsed
345+
break
346+
}
347+
}
339348

340349
summary := fiber.Map{
341-
"Title": "LocalAI - Chat with " + allModels[0],
350+
"Title": title,
342351
"BaseURL": utils.BaseURL(c),
343-
"AllModels": allModels,
344352
"ModelsWithoutConfig": modelsWithoutConfig,
345353
"ModelsConfig": backendConfigs,
346-
"Model": allModels[0],
354+
"Model": modelThatCanBeUsed,
347355
"Version": internal.PrintableVersion(),
348356
"IsP2PEnabled": p2p.IsP2PEnabled(),
349357
}
@@ -354,7 +362,6 @@ func RegisterUIRoutes(app *fiber.App,
354362

355363
// Show the Chat page
356364
app.Get("/chat/:model", func(c *fiber.Ctx) error {
357-
allModels, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
358365
backendConfigs := cl.GetAllBackendConfigs()
359366
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
360367

@@ -363,7 +370,6 @@ func RegisterUIRoutes(app *fiber.App,
363370
"BaseURL": utils.BaseURL(c),
364371
"ModelsConfig": backendConfigs,
365372
"ModelsWithoutConfig": modelsWithoutConfig,
366-
"AllModels": allModels,
367373
"Model": c.Params("model"),
368374
"Version": internal.PrintableVersion(),
369375
"IsP2PEnabled": p2p.IsP2PEnabled(),
@@ -375,36 +381,50 @@ func RegisterUIRoutes(app *fiber.App,
375381

376382
app.Get("/text2image/:model", func(c *fiber.Ctx) error {
377383
backendConfigs := cl.GetAllBackendConfigs()
384+
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
378385

379386
summary := fiber.Map{
380-
"Title": "LocalAI - Generate images with " + c.Params("model"),
381-
"BaseURL": utils.BaseURL(c),
382-
"ModelsConfig": backendConfigs,
383-
"Model": c.Params("model"),
384-
"Version": internal.PrintableVersion(),
385-
"IsP2PEnabled": p2p.IsP2PEnabled(),
387+
"Title": "LocalAI - Generate images with " + c.Params("model"),
388+
"BaseURL": utils.BaseURL(c),
389+
"ModelsConfig": backendConfigs,
390+
"ModelsWithoutConfig": modelsWithoutConfig,
391+
"Model": c.Params("model"),
392+
"Version": internal.PrintableVersion(),
393+
"IsP2PEnabled": p2p.IsP2PEnabled(),
386394
}
387395

388396
// Render index
389397
return c.Render("views/text2image", summary)
390398
})
391399

392400
app.Get("/text2image/", func(c *fiber.Ctx) error {
393-
394401
backendConfigs := cl.GetAllBackendConfigs()
402+
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
395403

396-
if len(backendConfigs) == 0 {
404+
if len(backendConfigs)+len(modelsWithoutConfig) == 0 {
397405
// If no model is available redirect to the index which suggests how to install models
398406
return c.Redirect(utils.BaseURL(c))
399407
}
400408

409+
modelThatCanBeUsed := ""
410+
title := "LocalAI - Generate images"
411+
412+
for _, b := range backendConfigs {
413+
if b.HasUsecases(config.FLAG_IMAGE) {
414+
modelThatCanBeUsed = b.Name
415+
title = "LocalAI - Generate images with " + modelThatCanBeUsed
416+
break
417+
}
418+
}
419+
401420
summary := fiber.Map{
402-
"Title": "LocalAI - Generate images with " + backendConfigs[0].Name,
403-
"BaseURL": utils.BaseURL(c),
404-
"ModelsConfig": backendConfigs,
405-
"Model": backendConfigs[0].Name,
406-
"Version": internal.PrintableVersion(),
407-
"IsP2PEnabled": p2p.IsP2PEnabled(),
421+
"Title": title,
422+
"BaseURL": utils.BaseURL(c),
423+
"ModelsConfig": backendConfigs,
424+
"ModelsWithoutConfig": modelsWithoutConfig,
425+
"Model": modelThatCanBeUsed,
426+
"Version": internal.PrintableVersion(),
427+
"IsP2PEnabled": p2p.IsP2PEnabled(),
408428
}
409429

410430
// Render index
@@ -413,36 +433,49 @@ func RegisterUIRoutes(app *fiber.App,
413433

414434
app.Get("/tts/:model", func(c *fiber.Ctx) error {
415435
backendConfigs := cl.GetAllBackendConfigs()
436+
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
416437

417438
summary := fiber.Map{
418-
"Title": "LocalAI - Generate images with " + c.Params("model"),
419-
"BaseURL": utils.BaseURL(c),
420-
"ModelsConfig": backendConfigs,
421-
"Model": c.Params("model"),
422-
"Version": internal.PrintableVersion(),
423-
"IsP2PEnabled": p2p.IsP2PEnabled(),
439+
"Title": "LocalAI - Generate images with " + c.Params("model"),
440+
"BaseURL": utils.BaseURL(c),
441+
"ModelsConfig": backendConfigs,
442+
"ModelsWithoutConfig": modelsWithoutConfig,
443+
"Model": c.Params("model"),
444+
"Version": internal.PrintableVersion(),
445+
"IsP2PEnabled": p2p.IsP2PEnabled(),
424446
}
425447

426448
// Render index
427449
return c.Render("views/tts", summary)
428450
})
429451

430452
app.Get("/tts/", func(c *fiber.Ctx) error {
431-
432453
backendConfigs := cl.GetAllBackendConfigs()
454+
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
433455

434-
if len(backendConfigs) == 0 {
456+
if len(backendConfigs)+len(modelsWithoutConfig) == 0 {
435457
// If no model is available redirect to the index which suggests how to install models
436458
return c.Redirect(utils.BaseURL(c))
437459
}
438460

461+
modelThatCanBeUsed := ""
462+
title := "LocalAI - Generate audio"
463+
464+
for _, b := range backendConfigs {
465+
if b.HasUsecases(config.FLAG_CHAT) {
466+
modelThatCanBeUsed = b.Name
467+
title = "LocalAI - Generate audio with " + modelThatCanBeUsed
468+
break
469+
}
470+
}
439471
summary := fiber.Map{
440-
"Title": "LocalAI - Generate audio with " + backendConfigs[0].Name,
441-
"BaseURL": utils.BaseURL(c),
442-
"ModelsConfig": backendConfigs,
443-
"Model": backendConfigs[0].Name,
444-
"IsP2PEnabled": p2p.IsP2PEnabled(),
445-
"Version": internal.PrintableVersion(),
472+
"Title": title,
473+
"BaseURL": utils.BaseURL(c),
474+
"ModelsConfig": backendConfigs,
475+
"ModelsWithoutConfig": modelsWithoutConfig,
476+
"Model": modelThatCanBeUsed,
477+
"IsP2PEnabled": p2p.IsP2PEnabled(),
478+
"Version": internal.PrintableVersion(),
446479
}
447480

448481
// Render index

core/http/views/chat.html

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<div class="flex items-center justify-between">
4646

47-
<h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat with {{.Model}} <a href="browse?term={{.Model}}" ><i class="fas fa-brain pr-2"></i></a> <a href="https://localai.io/features/text-generation/" target="_blank" >
47+
<h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat {{ if .Model }} with {{.Model}} {{ end }} <a href="browse?term={{.Model}}" ><i class="fas fa-brain pr-2"></i></a> <a href="https://localai.io/features/text-generation/" target="_blank" >
4848
<i class="fas fa-circle-info pr-2"></i>
4949
</a></h1>
5050
<div x-show="component === 'menu'" id="menu">
@@ -101,22 +101,14 @@ <h1 class="text-lg font-semibold"> <i class="fa-solid fa-comments"></i> Chat wit
101101
{{ $model:=.Model}}
102102
{{ range .ModelsConfig }}
103103
{{ $cfg := . }}
104-
{{ if eq .Name $model }}
105-
<option value="chat/{{.Name}}" selected class="bg-gray-700 text-white">{{.Name}}</option>
106-
{{ else }}
107-
{{ range .KnownUsecaseStrings }}
108-
{{ if eq . "FLAG_CHAT" }}
109-
<option value="chat/{{$cfg.Name}}" class="bg-gray-700 text-white">{{$cfg.Name}}</option>
110-
{{ end }}
104+
{{ range .KnownUsecaseStrings }}
105+
{{ if eq . "FLAG_CHAT" }}
106+
<option value="chat/{{$cfg.Name}}" {{ if eq $cfg.Name $model }} selected {{end}} class="bg-gray-700 text-white">{{$cfg.Name}}</option>
111107
{{ end }}
112108
{{ end }}
113109
{{ end }}
114110
{{ range .ModelsWithoutConfig }}
115-
{{ if eq . $model }}
116-
<option value="chat/{{.}}" selected class="bg-gray-700 text-white">{{.}}</option>
117-
{{ else }}
118-
<option value="chat/{{.}}" class="bg-gray-700 text-white">{{.}}</option>
119-
{{ end }}
111+
<option value="chat/{{.}}" {{ if eq . $model }} selected {{ end }} class="bg-gray-700 text-white">{{.}}</option>
120112
{{end}}
121113
</select>
122114
</div>

core/http/views/text2image.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="mt-12">
1414
<div class="flex items-center justify-center text-center pb-2">
1515
<span class="text-3xl font-semibold text-gray-100">
16-
🖼️ Text to Image
16+
🖼️ Text to Image {{ if .Model }} (using {{.Model}}) {{ end }}
1717
<a href="https://localai.io/features/image-generation" target="_blank" >
1818
<i class="fas fa-circle-info pr-2"></i>
1919
</a>
@@ -49,12 +49,16 @@
4949
<option value="" disabled class="text-gray-400" >Select a model</option>
5050
{{ $model:=.Model}}
5151
{{ range .ModelsConfig }}
52-
{{ if eq .Name $model }}
53-
<option value="text2image/{{.Name}}" selected class="bg-gray-700 text-white">{{.Name}}</option>
54-
{{ else }}
55-
<option value="text2image/{{.Name}}" class="bg-gray-700 text-white">{{.Name}}</option>
56-
{{ end }}
52+
{{ $cfg := . }}
53+
{{ range .KnownUsecaseStrings }}
54+
{{ if eq . "FLAG_IMAGE" }}
55+
<option value="text2image/{{$cfg.Name}}" {{ if eq $cfg.Name $model }} selected {{end}} class="bg-gray-700 text-white">{{$cfg.Name}}</option>
56+
{{ end }}
57+
{{ end }}
5758
{{ end }}
59+
{{ range .ModelsWithoutConfig }}
60+
<option value="text2image/{{.}}" {{ if eq . $model }} selected {{ end }} class="bg-gray-700 text-white">{{.}}</option>
61+
{{end}}
5862
</select>
5963

6064
</div>

core/http/views/tts.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="mt-12">
1212
<div class="flex items-center justify-center text-center pb-2">
1313
<span class="text-3xl font-semibold text-gray-100">
14-
<i class="fa-solid fa-music"></i> Text to speech/audio
14+
<i class="fa-solid fa-music"></i> Text to speech/audio {{ if .Model }} (using {{.Model}}) {{ end }}
1515
<a href="https://localai.io/features/text-to-audio/" target="_blank" >
1616
<i class="fas fa-circle-info pr-2"></i>
1717
</a>
@@ -46,12 +46,16 @@
4646
<option value="" disabled class="text-gray-400" >Select a model</option>
4747
{{ $model:=.Model}}
4848
{{ range .ModelsConfig }}
49-
{{ if eq .Name $model }}
50-
<option value="tts/{{.Name}}" selected class="bg-gray-700 text-white">{{.Name}}</option>
51-
{{ else }}
52-
<option value="tts/{{.Name}}" class="bg-gray-700 text-white">{{.Name}}</option>
53-
{{ end }}
49+
{{ $cfg := . }}
50+
{{ range .KnownUsecaseStrings }}
51+
{{ if eq . "FLAG_TTS" }}
52+
<option value="tts/{{$cfg.Name}}" {{ if eq $cfg.Name $model }} selected {{end}} class="bg-gray-700 text-white">{{$cfg.Name}}</option>
53+
{{ end }}
54+
{{ end }}
5455
{{ end }}
56+
{{ range .ModelsWithoutConfig }}
57+
<option value="tts/{{.}}" {{ if eq . $model }} selected {{ end }} class="bg-gray-700 text-white">{{.}}</option>
58+
{{end}}
5559
</select>
5660

5761
</div>

0 commit comments

Comments
 (0)