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-09-17 03:29:07 +00:00
|
|
|
galleryService *services.GalleryService) {
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
app.Get("/swagger/*", swagger.HandlerDefault) // default
|
|
|
|
|
|
|
|
// LocalAI API endpoints
|
2024-08-17 06:28:52 +00:00
|
|
|
if !appConfig.DisableGalleryEndpoint {
|
|
|
|
modelGalleryEndpointService := localai.CreateModelGalleryEndpointService(appConfig.Galleries, appConfig.ModelPath, galleryService)
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/models/apply", modelGalleryEndpointService.ApplyModelGalleryEndpoint())
|
|
|
|
app.Post("/models/delete/:name", modelGalleryEndpointService.DeleteModelGalleryEndpoint())
|
2024-08-17 06:28:52 +00:00
|
|
|
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/models/available", modelGalleryEndpointService.ListModelFromGalleryEndpoint())
|
|
|
|
app.Get("/models/galleries", modelGalleryEndpointService.ListModelGalleriesEndpoint())
|
|
|
|
app.Post("/models/galleries", modelGalleryEndpointService.AddModelGalleryEndpoint())
|
|
|
|
app.Delete("/models/galleries", modelGalleryEndpointService.RemoveModelGalleryEndpoint())
|
|
|
|
app.Get("/models/jobs/:uuid", modelGalleryEndpointService.GetOpStatusEndpoint())
|
|
|
|
app.Get("/models/jobs", modelGalleryEndpointService.GetAllStatusEndpoint())
|
2024-08-17 06:28:52 +00:00
|
|
|
}
|
2024-04-20 23:19:57 +00:00
|
|
|
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/tts", localai.TTSEndpoint(cl, ml, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// Stores
|
|
|
|
sl := model.NewModelLoader("")
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Post("/stores/set", localai.StoresSetEndpoint(sl, appConfig))
|
|
|
|
app.Post("/stores/delete", localai.StoresDeleteEndpoint(sl, appConfig))
|
|
|
|
app.Post("/stores/get", localai.StoresGetEndpoint(sl, appConfig))
|
|
|
|
app.Post("/stores/find", localai.StoresFindEndpoint(sl, appConfig))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/metrics", localai.LocalAIMetricsEndpoint())
|
2024-04-20 23:19:57 +00:00
|
|
|
|
|
|
|
// Experimental Backend Statistics Module
|
2024-04-29 17:42:37 +00:00
|
|
|
backendMonitorService := services.NewBackendMonitorService(ml, cl, appConfig) // Split out for now
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/backend/monitor", localai.BackendMonitorEndpoint(backendMonitorService))
|
|
|
|
app.Post("/backend/shutdown", localai.BackendShutdownEndpoint(backendMonitorService))
|
2024-04-20 23:19:57 +00:00
|
|
|
|
2024-07-08 20:04:06 +00:00
|
|
|
// p2p
|
|
|
|
if p2p.IsP2PEnabled() {
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/api/p2p", localai.ShowP2PNodes(appConfig))
|
|
|
|
app.Get("/api/p2p/token", localai.ShowP2PToken(appConfig))
|
2024-07-08 20:04:06 +00:00
|
|
|
}
|
|
|
|
|
2024-09-17 03:29:07 +00:00
|
|
|
app.Get("/version", func(c *fiber.Ctx) error {
|
2024-04-20 23:19:57 +00:00
|
|
|
return c.JSON(struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
}{Version: internal.PrintableVersion()})
|
|
|
|
})
|
|
|
|
|
2024-09-17 14:51:40 +00:00
|
|
|
app.Get("/system", localai.SystemInformations(ml, appConfig))
|
2024-09-05 18:44:30 +00:00
|
|
|
|
2024-04-20 23:19:57 +00:00
|
|
|
}
|