-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(routes): split routes registration (#2077)
Signed-off-by: Ettore Di Giacinto <[email protected]>
- Loading branch information
Showing
8 changed files
with
227 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package localai | ||
|
||
import ( | ||
"github.com/go-skynet/LocalAI/core/config" | ||
"github.com/go-skynet/LocalAI/internal" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func WelcomeEndpoint(appConfig *config.ApplicationConfig, | ||
models []string, backendConfigs []config.BackendConfig) func(*fiber.Ctx) error { | ||
return func(c *fiber.Ctx) error { | ||
summary := fiber.Map{ | ||
"Title": "LocalAI API - " + internal.PrintableVersion(), | ||
"Version": internal.PrintableVersion(), | ||
"Models": models, | ||
"ModelsConfig": backendConfigs, | ||
"ApplicationConfig": appConfig, | ||
} | ||
|
||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package routes | ||
|
||
import ( | ||
"github.com/go-skynet/LocalAI/core/config" | ||
"github.com/go-skynet/LocalAI/core/http/endpoints/elevenlabs" | ||
"github.com/go-skynet/LocalAI/pkg/model" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func RegisterElevenLabsRoutes(app *fiber.App, | ||
cl *config.BackendConfigLoader, | ||
ml *model.ModelLoader, | ||
appConfig *config.ApplicationConfig, | ||
auth func(*fiber.Ctx) error) { | ||
|
||
// Elevenlabs | ||
app.Post("/v1/text-to-speech/:voice-id", auth, elevenlabs.TTSEndpoint(cl, ml, appConfig)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package routes | ||
|
||
import ( | ||
"github.com/go-skynet/LocalAI/core/config" | ||
"github.com/go-skynet/LocalAI/core/http/endpoints/localai" | ||
"github.com/go-skynet/LocalAI/core/services" | ||
"github.com/go-skynet/LocalAI/internal" | ||
"github.com/go-skynet/LocalAI/pkg/model" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/swagger" | ||
) | ||
|
||
func RegisterLocalAIRoutes(app *fiber.App, | ||
cl *config.BackendConfigLoader, | ||
ml *model.ModelLoader, | ||
appConfig *config.ApplicationConfig, | ||
auth func(*fiber.Ctx) error) { | ||
|
||
app.Get("/swagger/*", swagger.HandlerDefault) // default | ||
|
||
// LocalAI API endpoints | ||
galleryService := services.NewGalleryService(appConfig.ModelPath) | ||
galleryService.Start(appConfig.Context, cl) | ||
|
||
modelGalleryEndpointService := localai.CreateModelGalleryEndpointService(appConfig.Galleries, appConfig.ModelPath, galleryService) | ||
app.Post("/models/apply", auth, modelGalleryEndpointService.ApplyModelGalleryEndpoint()) | ||
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 | ||
backendMonitor := services.NewBackendMonitor(cl, ml, appConfig) // Split out for now | ||
app.Get("/backend/monitor", auth, localai.BackendMonitorEndpoint(backendMonitor)) | ||
app.Post("/backend/shutdown", auth, localai.BackendShutdownEndpoint(backendMonitor)) | ||
|
||
app.Get("/version", auth, func(c *fiber.Ctx) error { | ||
return c.JSON(struct { | ||
Version string `json:"version"` | ||
}{Version: internal.PrintableVersion()}) | ||
}) | ||
|
||
} |
Oops, something went wrong.