mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-06 02:28:15 +00:00
docs(swagger): comment LocalAI gallery endpoints and rerankers (#2854)
* docs(swagger): comment LocalAI gallery endpoints and rerankers Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Update core/http/endpoints/jina/rerank.go Co-authored-by: Dave <dave@gray101.com> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> * Update core/http/endpoints/jina/rerank.go Co-authored-by: Dave <dave@gray101.com> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> * Update core/http/endpoints/localai/gallery.go Co-authored-by: Dave <dave@gray101.com> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> * Update core/http/endpoints/localai/gallery.go Co-authored-by: Dave <dave@gray101.com> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Co-authored-by: Dave <dave@gray101.com>
This commit is contained in:
parent
fc60031ac1
commit
fbd0a270b3
@ -12,6 +12,11 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"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 {
|
func JINARerankEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
req := new(schema.JINARerankRequest)
|
req := new(schema.JINARerankRequest)
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/mudler/LocalAI/core/config"
|
"github.com/mudler/LocalAI/core/config"
|
||||||
"github.com/mudler/LocalAI/core/gallery"
|
"github.com/mudler/LocalAI/core/gallery"
|
||||||
|
"github.com/mudler/LocalAI/core/schema"
|
||||||
"github.com/mudler/LocalAI/core/services"
|
"github.com/mudler/LocalAI/core/services"
|
||||||
"github.com/rs/zerolog/log"
|
"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 {
|
func (mgs *ModelGalleryEndpointService) ApplyModelGalleryEndpoint() func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
input := new(GalleryModel)
|
input := new(GalleryModel)
|
||||||
@ -68,13 +74,15 @@ func (mgs *ModelGalleryEndpointService) ApplyModelGalleryEndpoint() func(c *fibe
|
|||||||
Galleries: mgs.galleries,
|
Galleries: mgs.galleries,
|
||||||
ConfigURL: input.ConfigURL,
|
ConfigURL: input.ConfigURL,
|
||||||
}
|
}
|
||||||
return c.JSON(struct {
|
return c.JSON(schema.GalleryResponse{ID: uuid.String(), StatusURL: c.BaseURL() + "/models/jobs/" + uuid.String()})
|
||||||
ID string `json:"uuid"`
|
|
||||||
StatusURL string `json:"status"`
|
|
||||||
}{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 {
|
func (mgs *ModelGalleryEndpointService) DeleteModelGalleryEndpoint() func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
modelName := c.Params("name")
|
modelName := c.Params("name")
|
||||||
@ -89,13 +97,14 @@ func (mgs *ModelGalleryEndpointService) DeleteModelGalleryEndpoint() func(c *fib
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(struct {
|
return c.JSON(schema.GalleryResponse{ID: uuid.String(), StatusURL: c.BaseURL() + "/models/jobs/" + uuid.String()})
|
||||||
ID string `json:"uuid"`
|
|
||||||
StatusURL string `json:"status"`
|
|
||||||
}{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 {
|
func (mgs *ModelGalleryEndpointService) ListModelFromGalleryEndpoint() func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
log.Debug().Msgf("Listing models from galleries: %+v", mgs.galleries)
|
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!
|
// 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 {
|
func (mgs *ModelGalleryEndpointService) ListModelGalleriesEndpoint() func(c *fiber.Ctx) error {
|
||||||
return 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 {
|
func (mgs *ModelGalleryEndpointService) AddModelGalleryEndpoint() func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
input := new(config.Gallery)
|
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 {
|
func (mgs *ModelGalleryEndpointService) RemoveModelGalleryEndpoint() func(c *fiber.Ctx) error {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
input := new(config.Gallery)
|
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 {
|
mgs.galleries = slices.DeleteFunc(mgs.galleries, func(gallery config.Gallery) bool {
|
||||||
return gallery.Name == input.Name
|
return gallery.Name == input.Name
|
||||||
})
|
})
|
||||||
return c.Send(nil)
|
dat, err := json.Marshal(mgs.galleries)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.Send(dat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,11 @@ type BackendMonitorResponse struct {
|
|||||||
CPUPercent float64
|
CPUPercent float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GalleryResponse struct {
|
||||||
|
ID string `json:"uuid"`
|
||||||
|
StatusURL string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
// @Description TTS request body
|
// @Description TTS request body
|
||||||
type TTSRequest struct {
|
type TTSRequest struct {
|
||||||
Model string `json:"model" yaml:"model"` // model name or full path
|
Model string `json:"model" yaml:"model"` // model name or full path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user