[API] expose all the jobs via /models/jobs endpoint (#983)

**Description**

This PR fixes #


**Notes for Reviewers**


**[Signed
commits](../CONTRIBUTING.md#signing-off-on-commits-developer-certificate-of-origin)**
- [ ] Yes, I signed my commits.
 

<!--
Thank you for contributing to LocalAI! 

Contributing Conventions:

1. Include descriptive PR titles with [<component-name>] prepended.
2. Build and test your changes before submitting a PR. 
3. Sign your commits

By following the community's contribution conventions upfront, the
review process will
be accelerated and your PR merged more quickly.
-->

Co-authored-by: Jirubizu <jirubizu@jirubizu.cc>
This commit is contained in:
Jirubizu 2023-08-31 16:03:03 +01:00 committed by GitHub
parent 629185e10a
commit 355e9d4fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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.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/available", auth, localai.ListModelFromGalleryEndpoint(options.Galleries, options.Loader.ModelPath))
app.Get("/models/jobs/:uuid", auth, localai.GetOpStatusEndpoint(galleryService)) app.Get("/models/jobs/:uuid", auth, localai.GetOpStatusEndpoint(galleryService))
app.Get("/models/jobs", auth, localai.GetAllStatusEndpoint(galleryService))
// openAI compatible API endpoint // openAI compatible API endpoint

View File

@ -27,6 +27,7 @@ type galleryOp struct {
} }
type galleryOpStatus struct { type galleryOpStatus struct {
FileName string `json:"file_name"`
Error error `json:"error"` Error error `json:"error"`
Processed bool `json:"processed"` Processed bool `json:"processed"`
Message string `json:"message"` Message string `json:"message"`
@ -76,6 +77,13 @@ func (g *galleryApplier) getStatus(s string) *galleryOpStatus {
return g.statuses[s] 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) { func (g *galleryApplier) Start(c context.Context, cm *config.ConfigLoader) {
go func() { go func() {
for { for {
@ -94,7 +102,7 @@ func (g *galleryApplier) Start(c context.Context, cm *config.ConfigLoader) {
// displayDownload displays the download progress // displayDownload displays the download progress
progressCallback := func(fileName string, current string, total string, percentage float64) { 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) 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 { type GalleryModel struct {
ID string `json:"id"` ID string `json:"id"`
gallery.GalleryModel gallery.GalleryModel