@@ -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
0 commit comments