mirror of
https://github.com/mudler/LocalAI.git
synced 2025-01-30 16:14:33 +00:00
fix(gallery): do clear out errors once displayed (#3033)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
2a839e1432
commit
d6a7a77f6b
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/mudler/LocalAI/core/gallery"
|
"github.com/mudler/LocalAI/core/gallery"
|
||||||
"github.com/mudler/LocalAI/core/p2p"
|
"github.com/mudler/LocalAI/core/p2p"
|
||||||
"github.com/mudler/LocalAI/core/services"
|
"github.com/mudler/LocalAI/core/services"
|
||||||
"github.com/mudler/LocalAI/pkg/xsync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -372,7 +371,12 @@ func dropBadChars(s string) string {
|
|||||||
return strings.ReplaceAll(s, "@", "__")
|
return strings.ReplaceAll(s, "@", "__")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListModels(models []*gallery.GalleryModel, processing *xsync.SyncedMap[string, string], galleryService *services.GalleryService) string {
|
type ProcessTracker interface {
|
||||||
|
Exists(string) bool
|
||||||
|
Get(string) string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListModels(models []*gallery.GalleryModel, processTracker ProcessTracker, galleryService *services.GalleryService) string {
|
||||||
modelsElements := []elem.Node{}
|
modelsElements := []elem.Node{}
|
||||||
descriptionDiv := func(m *gallery.GalleryModel) elem.Node {
|
descriptionDiv := func(m *gallery.GalleryModel) elem.Node {
|
||||||
return elem.Div(
|
return elem.Div(
|
||||||
@ -396,7 +400,7 @@ func ListModels(models []*gallery.GalleryModel, processing *xsync.SyncedMap[stri
|
|||||||
|
|
||||||
actionDiv := func(m *gallery.GalleryModel) elem.Node {
|
actionDiv := func(m *gallery.GalleryModel) elem.Node {
|
||||||
galleryID := fmt.Sprintf("%s@%s", m.Gallery.Name, m.Name)
|
galleryID := fmt.Sprintf("%s@%s", m.Gallery.Name, m.Name)
|
||||||
currentlyProcessing := processing.Exists(galleryID)
|
currentlyProcessing := processTracker.Exists(galleryID)
|
||||||
jobID := ""
|
jobID := ""
|
||||||
isDeletionOp := false
|
isDeletionOp := false
|
||||||
if currentlyProcessing {
|
if currentlyProcessing {
|
||||||
@ -404,7 +408,7 @@ func ListModels(models []*gallery.GalleryModel, processing *xsync.SyncedMap[stri
|
|||||||
if status != nil && status.Deletion {
|
if status != nil && status.Deletion {
|
||||||
isDeletionOp = true
|
isDeletionOp = true
|
||||||
}
|
}
|
||||||
jobID = processing.Get(galleryID)
|
jobID = processTracker.Get(galleryID)
|
||||||
// TODO:
|
// TODO:
|
||||||
// case not handled, if status == nil : "Waiting"
|
// case not handled, if status == nil : "Waiting"
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,40 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type modelOpCache struct {
|
||||||
|
status *xsync.SyncedMap[string, string]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewModelOpCache() *modelOpCache {
|
||||||
|
return &modelOpCache{
|
||||||
|
status: xsync.NewSyncedMap[string, string](),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *modelOpCache) Set(key string, value string) {
|
||||||
|
m.status.Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *modelOpCache) Get(key string) string {
|
||||||
|
return m.status.Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *modelOpCache) DeleteUUID(uuid string) {
|
||||||
|
for _, k := range m.status.Keys() {
|
||||||
|
if m.status.Get(k) == uuid {
|
||||||
|
m.status.Delete(k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *modelOpCache) Map() map[string]string {
|
||||||
|
return m.status.Map()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *modelOpCache) Exists(key string) bool {
|
||||||
|
return m.status.Exists(key)
|
||||||
|
}
|
||||||
|
|
||||||
func RegisterUIRoutes(app *fiber.App,
|
func RegisterUIRoutes(app *fiber.App,
|
||||||
cl *config.BackendConfigLoader,
|
cl *config.BackendConfigLoader,
|
||||||
ml *model.ModelLoader,
|
ml *model.ModelLoader,
|
||||||
@ -29,7 +63,7 @@ func RegisterUIRoutes(app *fiber.App,
|
|||||||
auth func(*fiber.Ctx) error) {
|
auth func(*fiber.Ctx) error) {
|
||||||
|
|
||||||
// keeps the state of models that are being installed from the UI
|
// keeps the state of models that are being installed from the UI
|
||||||
var processingModels = xsync.NewSyncedMap[string, string]()
|
var processingModels = NewModelOpCache()
|
||||||
|
|
||||||
// modelStatus returns the current status of the models being processed (installation or deletion)
|
// modelStatus returns the current status of the models being processed (installation or deletion)
|
||||||
// it is called asynchonously from the UI
|
// it is called asynchonously from the UI
|
||||||
@ -232,6 +266,8 @@ func RegisterUIRoutes(app *fiber.App,
|
|||||||
return c.SendString(elements.ProgressBar("100"))
|
return c.SendString(elements.ProgressBar("100"))
|
||||||
}
|
}
|
||||||
if status.Error != nil {
|
if status.Error != nil {
|
||||||
|
// TODO: instead of deleting the job, we should keep it in the cache and make it dismissable
|
||||||
|
processingModels.DeleteUUID(jobUID)
|
||||||
return c.SendString(elements.ErrorProgress(status.Error.Error(), status.GalleryModelName))
|
return c.SendString(elements.ErrorProgress(status.Error.Error(), status.GalleryModelName))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,12 +282,7 @@ func RegisterUIRoutes(app *fiber.App,
|
|||||||
status := galleryService.GetStatus(jobUID)
|
status := galleryService.GetStatus(jobUID)
|
||||||
|
|
||||||
galleryID := ""
|
galleryID := ""
|
||||||
for _, k := range processingModels.Keys() {
|
processingModels.DeleteUUID(jobUID)
|
||||||
if processingModels.Get(k) == jobUID {
|
|
||||||
galleryID = k
|
|
||||||
processingModels.Delete(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if galleryID == "" {
|
if galleryID == "" {
|
||||||
log.Debug().Msgf("no processing model found for job : %+v\n", jobUID)
|
log.Debug().Msgf("no processing model found for job : %+v\n", jobUID)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user