diff --git a/api/api.go b/api/api.go index c07077d9..6a16130b 100644 --- a/api/api.go +++ b/api/api.go @@ -171,6 +171,7 @@ func App(opts ...options.AppOption) (*fiber.App, error) { app.Post("/models/apply", auth, localai.ApplyModelGalleryEndpoint(options.Loader.ModelPath, cl, galleryService.C, options.Galleries)) app.Get("/models/available", auth, localai.ListModelFromGalleryEndpoint(options.Galleries, options.Loader.ModelPath)) app.Get("/models/jobs/:uuid", auth, localai.GetOpStatusEndpoint(galleryService)) + app.Get("/models/jobs", auth, localai.GetAllStatusEndpoint(galleryService)) // openAI compatible API endpoint diff --git a/api/localai/gallery.go b/api/localai/gallery.go index c15ab553..7e6bcb67 100644 --- a/api/localai/gallery.go +++ b/api/localai/gallery.go @@ -27,6 +27,7 @@ type galleryOp struct { } type galleryOpStatus struct { + FileName string `json:"file_name"` Error error `json:"error"` Processed bool `json:"processed"` Message string `json:"message"` @@ -76,6 +77,13 @@ func (g *galleryApplier) getStatus(s string) *galleryOpStatus { return g.statuses[s] } +func (g *galleryApplier) getAllStatus() map[string]*galleryOpStatus { + g.Lock() + defer g.Unlock() + + return g.statuses +} + func (g *galleryApplier) Start(c context.Context, cm *config.ConfigLoader) { go func() { for { @@ -94,7 +102,7 @@ func (g *galleryApplier) Start(c context.Context, cm *config.ConfigLoader) { // displayDownload displays the download progress progressCallback := func(fileName string, current string, total string, percentage float64) { - g.updateStatus(op.id, &galleryOpStatus{Message: "processing", Progress: percentage, TotalFileSize: total, DownloadedFileSize: current}) + g.updateStatus(op.id, &galleryOpStatus{Message: "processing", FileName: fileName, Progress: percentage, TotalFileSize: total, DownloadedFileSize: current}) utils.DisplayDownloadFunction(fileName, current, total, percentage) } @@ -190,6 +198,12 @@ func GetOpStatusEndpoint(g *galleryApplier) func(c *fiber.Ctx) error { } } +func GetAllStatusEndpoint(g *galleryApplier) func(c *fiber.Ctx) error { + return func(c *fiber.Ctx) error { + return c.JSON(g.getAllStatus()) + } +} + type GalleryModel struct { ID string `json:"id"` gallery.GalleryModel