2024-04-20 23:19:57 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/gofiber/swagger"
|
2024-06-23 08:24:36 +00:00
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
|
|
"github.com/mudler/LocalAI/core/http/endpoints/localai"
|
2024-07-08 20:04:06 +00:00
|
|
|
"github.com/mudler/LocalAI/core/p2p"
|
2024-06-23 08:24:36 +00:00
|
|
|
"github.com/mudler/LocalAI/core/services"
|
|
|
|
"github.com/mudler/LocalAI/internal"
|
|
|
|
"github.com/mudler/LocalAI/pkg/model"
|
2024-04-20 23:19:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterLocalAIRoutes(app *fiber.App,
|
|
|
|
cl *config.BackendConfigLoader,
|
|
|
|
ml *model.ModelLoader,
|
|
|
|
appConfig *config.ApplicationConfig,
|
2024-04-23 07:22:58 +00:00
|
|
|
galleryService *services.GalleryService,
|
2024-04-20 23:19:57 +00:00
|
|
|
auth func(*fiber.Ctx) error) {
|
|
|
|
|
|
|
|
app.Get("/swagger/*", swagger.HandlerDefault) // default
|
|
|
|
|
|
|
|
// LocalAI API endpoints
|
|
|
|
|
|
|
|
modelGalleryEndpointService := localai.CreateModelGalleryEndpointService(appConfig.Galleries, appConfig.ModelPath, galleryService)
|
|
|
|
app.Post("/models/apply", auth, modelGalleryEndpointService.ApplyModelGalleryEndpoint())
|
2024-04-28 21:42:46 +00:00
|
|
|
app.Post("/models/delete/:name", auth, modelGalleryEndpointService.DeleteModelGalleryEndpoint())
|
|
|
|
|
2024-04-20 23:19:57 +00:00
|
|
|
app.Get("/models/available", auth, modelGalleryEndpointService.ListModelFromGalleryEndpoint())
|
|
|
|
app.Get("/models/galleries", auth, modelGalleryEndpointService.ListModelGalleriesEndpoint())
|
|
|
|
app.Post("/models/galleries", auth, modelGalleryEndpointService.AddModelGalleryEndpoint())
|
|
|
|
app.Delete("/models/galleries", auth, modelGalleryEndpointService.RemoveModelGalleryEndpoint())
|
|
|
|
app.Get("/models/jobs/:uuid", auth, modelGalleryEndpointService.GetOpStatusEndpoint())
|
|
|
|
app.Get("/models/jobs", auth, modelGalleryEndpointService.GetAllStatusEndpoint())
|
|
|
|
|
|
|
|
app.Post("/tts", auth, localai.TTSEndpoint(cl, ml, appConfig))
|
|
|
|
|
|
|
|
// Stores
|
|
|
|
sl := model.NewModelLoader("")
|
|
|
|
app.Post("/stores/set", auth, localai.StoresSetEndpoint(sl, appConfig))
|
|
|
|
app.Post("/stores/delete", auth, localai.StoresDeleteEndpoint(sl, appConfig))
|
|
|
|
app.Post("/stores/get", auth, localai.StoresGetEndpoint(sl, appConfig))
|
|
|
|
app.Post("/stores/find", auth, localai.StoresFindEndpoint(sl, appConfig))
|
|
|
|
|
|
|
|
// Kubernetes health checks
|
|
|
|
ok := func(c *fiber.Ctx) error {
|
|
|
|
return c.SendStatus(200)
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Get("/healthz", ok)
|
|
|
|
app.Get("/readyz", ok)
|
|
|
|
|
|
|
|
app.Get("/metrics", auth, localai.LocalAIMetricsEndpoint())
|
|
|
|
|
|
|
|
// Experimental Backend Statistics Module
|
2024-04-29 17:42:37 +00:00
|
|
|
backendMonitorService := services.NewBackendMonitorService(ml, cl, appConfig) // Split out for now
|
|
|
|
app.Get("/backend/monitor", auth, localai.BackendMonitorEndpoint(backendMonitorService))
|
|
|
|
app.Post("/backend/shutdown", auth, localai.BackendShutdownEndpoint(backendMonitorService))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
2024-07-08 20:04:06 +00:00
|
|
|
// p2p
|
|
|
|
if p2p.IsP2PEnabled() {
|
2024-08-07 21:35:44 +00:00
|
|
|
app.Get("/api/p2p", auth, localai.ShowP2PNodes(appConfig))
|
2024-07-15 06:31:38 +00:00
|
|
|
app.Get("/api/p2p/token", auth, localai.ShowP2PToken(appConfig))
|
2024-07-08 20:04:06 +00:00
|
|
|
}
|
|
|
|
|
2024-04-20 23:19:57 +00:00
|
|
|
app.Get("/version", auth, func(c *fiber.Ctx) error {
|
|
|
|
return c.JSON(struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
}{Version: internal.PrintableVersion()})
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|