2024-04-20 23:19:57 +00:00
|
|
|
package localai
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-06-23 08:24:36 +00:00
|
|
|
"github.com/mudler/LocalAI/core/config"
|
2024-06-24 15:32:12 +00:00
|
|
|
"github.com/mudler/LocalAI/core/gallery"
|
2024-07-08 20:04:06 +00:00
|
|
|
"github.com/mudler/LocalAI/core/p2p"
|
2024-07-10 13:28:39 +00:00
|
|
|
"github.com/mudler/LocalAI/core/services"
|
2024-06-23 08:24:36 +00:00
|
|
|
"github.com/mudler/LocalAI/internal"
|
|
|
|
"github.com/mudler/LocalAI/pkg/model"
|
2024-04-20 23:19:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func WelcomeEndpoint(appConfig *config.ApplicationConfig,
|
2024-05-07 22:42:34 +00:00
|
|
|
cl *config.BackendConfigLoader, ml *model.ModelLoader, modelStatus func() (map[string]string, map[string]string)) func(*fiber.Ctx) error {
|
2024-04-20 23:19:57 +00:00
|
|
|
return func(c *fiber.Ctx) error {
|
2024-04-23 07:22:58 +00:00
|
|
|
backendConfigs := cl.GetAllBackendConfigs()
|
2024-05-06 23:17:07 +00:00
|
|
|
galleryConfigs := map[string]*gallery.Config{}
|
2024-08-01 15:27:40 +00:00
|
|
|
|
2024-05-06 23:17:07 +00:00
|
|
|
for _, m := range backendConfigs {
|
|
|
|
cfg, err := gallery.GetLocalModelConfiguration(ml.ModelPath, m.Name)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
galleryConfigs[m.Name] = cfg
|
|
|
|
}
|
|
|
|
|
2024-10-11 21:49:00 +00:00
|
|
|
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
|
2024-10-11 15:30:14 +00:00
|
|
|
|
2024-05-07 22:42:34 +00:00
|
|
|
// Get model statuses to display in the UI the operation in progress
|
|
|
|
processingModels, taskTypes := modelStatus()
|
|
|
|
|
2024-04-20 23:19:57 +00:00
|
|
|
summary := fiber.Map{
|
|
|
|
"Title": "LocalAI API - " + internal.PrintableVersion(),
|
|
|
|
"Version": internal.PrintableVersion(),
|
2024-10-11 15:30:14 +00:00
|
|
|
"Models": modelsWithoutConfig,
|
2024-04-20 23:19:57 +00:00
|
|
|
"ModelsConfig": backendConfigs,
|
2024-05-06 23:17:07 +00:00
|
|
|
"GalleryConfig": galleryConfigs,
|
2024-07-08 20:04:06 +00:00
|
|
|
"IsP2PEnabled": p2p.IsP2PEnabled(),
|
2024-04-20 23:19:57 +00:00
|
|
|
"ApplicationConfig": appConfig,
|
2024-05-07 22:42:34 +00:00
|
|
|
"ProcessingModels": processingModels,
|
|
|
|
"TaskTypes": taskTypes,
|
2024-04-20 23:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if string(c.Context().Request.Header.ContentType()) == "application/json" || len(c.Accepts("html")) == 0 {
|
|
|
|
// The client expects a JSON response
|
|
|
|
return c.Status(fiber.StatusOK).JSON(summary)
|
|
|
|
} else {
|
|
|
|
// Render index
|
|
|
|
return c.Render("views/index", summary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|