2024-04-20 23:19:57 +00:00
|
|
|
package localai
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-skynet/LocalAI/core/config"
|
|
|
|
"github.com/go-skynet/LocalAI/internal"
|
2024-05-06 23:17:07 +00:00
|
|
|
"github.com/go-skynet/LocalAI/pkg/gallery"
|
2024-04-23 07:22:58 +00:00
|
|
|
"github.com/go-skynet/LocalAI/pkg/model"
|
2024-04-20 23:19:57 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
models, _ := ml.ListModels()
|
|
|
|
backendConfigs := cl.GetAllBackendConfigs()
|
|
|
|
|
2024-05-06 23:17:07 +00:00
|
|
|
galleryConfigs := map[string]*gallery.Config{}
|
|
|
|
for _, m := range backendConfigs {
|
|
|
|
|
|
|
|
cfg, err := gallery.GetLocalModelConfiguration(ml.ModelPath, m.Name)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
galleryConfigs[m.Name] = cfg
|
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
"Models": models,
|
|
|
|
"ModelsConfig": backendConfigs,
|
2024-05-06 23:17:07 +00:00
|
|
|
"GalleryConfig": galleryConfigs,
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|