Skip to content

Commit ea0c9f1

Browse files
authored
feat(ui): show only text models in the chat interface (#4869)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 08311f2 commit ea0c9f1

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed

core/http/routes/ui.go

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -305,23 +305,6 @@ func RegisterUIRoutes(app *fiber.App,
305305
})
306306
}
307307

308-
// Show the Chat page
309-
app.Get("/chat/:model", func(c *fiber.Ctx) error {
310-
backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
311-
312-
summary := fiber.Map{
313-
"Title": "LocalAI - Chat with " + c.Params("model"),
314-
"BaseURL": utils.BaseURL(c),
315-
"ModelsConfig": backendConfigs,
316-
"Model": c.Params("model"),
317-
"Version": internal.PrintableVersion(),
318-
"IsP2PEnabled": p2p.IsP2PEnabled(),
319-
}
320-
321-
// Render index
322-
return c.Render("views/chat", summary)
323-
})
324-
325308
app.Get("/talk/", func(c *fiber.Ctx) error {
326309
backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
327310

@@ -345,20 +328,45 @@ func RegisterUIRoutes(app *fiber.App,
345328

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

348-
backendConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
331+
allModels, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
332+
backendConfigs := cl.GetAllBackendConfigs()
333+
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
349334

350-
if len(backendConfigs) == 0 {
335+
if len(allModels) == 0 {
351336
// If no model is available redirect to the index which suggests how to install models
352337
return c.Redirect(utils.BaseURL(c))
353338
}
354339

355340
summary := fiber.Map{
356-
"Title": "LocalAI - Chat with " + backendConfigs[0],
357-
"BaseURL": utils.BaseURL(c),
358-
"ModelsConfig": backendConfigs,
359-
"Model": backendConfigs[0],
360-
"Version": internal.PrintableVersion(),
361-
"IsP2PEnabled": p2p.IsP2PEnabled(),
341+
"Title": "LocalAI - Chat with " + allModels[0],
342+
"BaseURL": utils.BaseURL(c),
343+
"AllModels": allModels,
344+
"ModelsWithoutConfig": modelsWithoutConfig,
345+
"ModelsConfig": backendConfigs,
346+
"Model": allModels[0],
347+
"Version": internal.PrintableVersion(),
348+
"IsP2PEnabled": p2p.IsP2PEnabled(),
349+
}
350+
351+
// Render index
352+
return c.Render("views/chat", summary)
353+
})
354+
355+
// Show the Chat page
356+
app.Get("/chat/:model", func(c *fiber.Ctx) error {
357+
allModels, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
358+
backendConfigs := cl.GetAllBackendConfigs()
359+
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
360+
361+
summary := fiber.Map{
362+
"Title": "LocalAI - Chat with " + c.Params("model"),
363+
"BaseURL": utils.BaseURL(c),
364+
"ModelsConfig": backendConfigs,
365+
"ModelsWithoutConfig": modelsWithoutConfig,
366+
"AllModels": allModels,
367+
"Model": c.Params("model"),
368+
"Version": internal.PrintableVersion(),
369+
"IsP2PEnabled": p2p.IsP2PEnabled(),
362370
}
363371

364372
// Render index

core/http/views/chat.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,25 @@ <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 . $model }}
104-
<option value="chat/{{.}}" selected class="bg-gray-700 text-white">{{.}}</option>
105-
{{ else }}
106-
<option value="chat/{{.}}" class="bg-gray-700 text-white">{{.}}</option>
107-
{{ end }}
103+
{{ $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 }}
111+
{{ end }}
112+
{{ end }}
108113
{{ end }}
114+
{{ 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 }}
120+
{{end}}
109121
</select>
110-
111122
</div>
112123
</div>
113124

core/http/views/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ <h2 class="text-center text-3xl font-semibold text-gray-100">{{$modelsN}} Instal
5050
{{$galleryConfig:=.GalleryConfig}}
5151
{{$noicon:="https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg"}}
5252
{{ range .ModelsConfig }}
53+
{{ $backendCfg := . }}
5354
{{ $cfg:= index $galleryConfig .Name}}
5455
<tr class="bg-gray-800 border-b border-gray-700">
5556
<td class="px-4 py-3">
@@ -69,13 +70,13 @@ <h2 class="text-center text-3xl font-semibold text-gray-100">{{$modelsN}} Instal
6970
<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>
7071
{{ range .KnownUsecaseStrings }}
7172
{{ if eq . "FLAG_CHAT" }}
72-
<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>
73+
<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>
7374
{{ end }}
7475
{{ if eq . "FLAG_IMAGE" }}
75-
<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>
76+
<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>
7677
{{ end }}
7778
{{ if eq . "FLAG_TTS" }}
78-
<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>
79+
<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>
7980
{{ end }}
8081
{{ end }}
8182
</td>

0 commit comments

Comments
 (0)