diff --git a/core/http/endpoints/jina/rerank.go b/core/http/endpoints/jina/rerank.go index ddeee745..04fdf031 100644 --- a/core/http/endpoints/jina/rerank.go +++ b/core/http/endpoints/jina/rerank.go @@ -12,6 +12,11 @@ import ( "github.com/rs/zerolog/log" ) +// JINARerankEndpoint acts like the Jina reranker endpoint (https://jina.ai/reranker/) +// @Summary Reranks a list of phrases by relevance to a given text query. +// @Param request body schema.JINARerankRequest true "query params" +// @Success 200 {object} schema.JINARerankResponse "Response" +// @Router /v1/rerank [post] func JINARerankEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { req := new(schema.JINARerankRequest) diff --git a/core/http/endpoints/localai/gallery.go b/core/http/endpoints/localai/gallery.go index 9c49d641..eaa4bedc 100644 --- a/core/http/endpoints/localai/gallery.go +++ b/core/http/endpoints/localai/gallery.go @@ -9,6 +9,7 @@ import ( "github.com/google/uuid" "github.com/mudler/LocalAI/core/config" "github.com/mudler/LocalAI/core/gallery" + "github.com/mudler/LocalAI/core/schema" "github.com/mudler/LocalAI/core/services" "github.com/rs/zerolog/log" ) @@ -49,6 +50,11 @@ func (mgs *ModelGalleryEndpointService) GetAllStatusEndpoint() func(c *fiber.Ctx } } +// ApplyModelGalleryEndpoint installs a new model to a LocalAI instance from the model gallery +// @Summary Install models to LocalAI. +// @Param request body GalleryModel true "query params" +// @Success 200 {object} schema.GalleryResponse "Response" +// @Router /models/apply [post] func (mgs *ModelGalleryEndpointService) ApplyModelGalleryEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { input := new(GalleryModel) @@ -68,13 +74,15 @@ func (mgs *ModelGalleryEndpointService) ApplyModelGalleryEndpoint() func(c *fibe Galleries: mgs.galleries, ConfigURL: input.ConfigURL, } - return c.JSON(struct { - ID string `json:"uuid"` - StatusURL string `json:"status"` - }{ID: uuid.String(), StatusURL: c.BaseURL() + "/models/jobs/" + uuid.String()}) + return c.JSON(schema.GalleryResponse{ID: uuid.String(), StatusURL: c.BaseURL() + "/models/jobs/" + uuid.String()}) } } +// DeleteModelGalleryEndpoint lets delete models from a LocalAI instance +// @Summary delete models to LocalAI. +// @Param name path string true "Model name" +// @Success 200 {object} schema.GalleryResponse "Response" +// @Router /models/delete/{name} [post] func (mgs *ModelGalleryEndpointService) DeleteModelGalleryEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { modelName := c.Params("name") @@ -89,13 +97,14 @@ func (mgs *ModelGalleryEndpointService) DeleteModelGalleryEndpoint() func(c *fib return err } - return c.JSON(struct { - ID string `json:"uuid"` - StatusURL string `json:"status"` - }{ID: uuid.String(), StatusURL: c.BaseURL() + "/models/jobs/" + uuid.String()}) + return c.JSON(schema.GalleryResponse{ID: uuid.String(), StatusURL: c.BaseURL() + "/models/jobs/" + uuid.String()}) } } +// ListModelFromGalleryEndpoint list the available models for installation from the active galleries +// @Summary List installable models. +// @Success 200 {object} []gallery.GalleryModel "Response" +// @Router /models/available [get] func (mgs *ModelGalleryEndpointService) ListModelFromGalleryEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { log.Debug().Msgf("Listing models from galleries: %+v", mgs.galleries) @@ -116,6 +125,10 @@ func (mgs *ModelGalleryEndpointService) ListModelFromGalleryEndpoint() func(c *f } } +// ListModelGalleriesEndpoint list the available galleries configured in LocalAI +// @Summary List all Galleries +// @Success 200 {object} []config.Gallery "Response" +// @Router /models/galleries [get] // NOTE: This is different (and much simpler!) than above! This JUST lists the model galleries that have been loaded, not their contents! func (mgs *ModelGalleryEndpointService) ListModelGalleriesEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { @@ -128,6 +141,11 @@ func (mgs *ModelGalleryEndpointService) ListModelGalleriesEndpoint() func(c *fib } } +// AddModelGalleryEndpoint adds a gallery in LocalAI +// @Summary Adds a gallery in LocalAI +// @Param request body config.Gallery true "Gallery details" +// @Success 200 {object} []config.Gallery "Response" +// @Router /models/galleries [post] func (mgs *ModelGalleryEndpointService) AddModelGalleryEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { input := new(config.Gallery) @@ -150,6 +168,11 @@ func (mgs *ModelGalleryEndpointService) AddModelGalleryEndpoint() func(c *fiber. } } +// RemoveModelGalleryEndpoint remove a gallery in LocalAI +// @Summary removes a gallery from LocalAI +// @Param request body config.Gallery true "Gallery details" +// @Success 200 {object} []config.Gallery "Response" +// @Router /models/galleries [delete] func (mgs *ModelGalleryEndpointService) RemoveModelGalleryEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { input := new(config.Gallery) @@ -165,6 +188,10 @@ func (mgs *ModelGalleryEndpointService) RemoveModelGalleryEndpoint() func(c *fib mgs.galleries = slices.DeleteFunc(mgs.galleries, func(gallery config.Gallery) bool { return gallery.Name == input.Name }) - return c.Send(nil) + dat, err := json.Marshal(mgs.galleries) + if err != nil { + return err + } + return c.Send(dat) } } diff --git a/core/schema/localai.go b/core/schema/localai.go index 9bbfe28b..3253143e 100644 --- a/core/schema/localai.go +++ b/core/schema/localai.go @@ -14,6 +14,11 @@ type BackendMonitorResponse struct { CPUPercent float64 } +type GalleryResponse struct { + ID string `json:"uuid"` + StatusURL string `json:"status"` +} + // @Description TTS request body type TTSRequest struct { Model string `json:"model" yaml:"model"` // model name or full path