Skip to content

Commit 7aed9e3

Browse files
committed
minor improvements
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent ecb7250 commit 7aed9e3

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

core/http/elements/gallery.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,20 @@ func cardSpan(text, icon string) elem.Node {
106106
func ListModels(models []*gallery.GalleryModel, installing *xsync.SyncedMap[string, string]) string {
107107
//StartProgressBar(uid, "0")
108108
modelsElements := []elem.Node{}
109-
span := func(s string) elem.Node {
110-
return elem.Span(
111-
attrs.Props{
112-
"class": "float-right inline-block bg-green-500 text-white py-1 px-3 rounded-full text-xs",
113-
},
114-
elem.Text(s),
115-
)
116-
}
109+
// span := func(s string) elem.Node {
110+
// return elem.Span(
111+
// attrs.Props{
112+
// "class": "float-right inline-block bg-green-500 text-white py-1 px-3 rounded-full text-xs",
113+
// },
114+
// elem.Text(s),
115+
// )
116+
// }
117117
deleteButton := func(m *gallery.GalleryModel) elem.Node {
118118
return elem.Button(
119119
attrs.Props{
120120
"data-twe-ripple-init": "",
121121
"data-twe-ripple-color": "light",
122-
"class": "float-right inline-block rounded bg-primary px-6 pb-2.5 mb-3 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong",
122+
"class": "float-right inline-block rounded bg-red-800 px-6 pb-2.5 mb-3 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-red-accent-300 hover:shadow-red-2 focus:bg-red-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-red-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong",
123123
"hx-swap": "outerHTML",
124124
// post the Model ID as param
125125
"hx-post": "/browse/delete/model/" + m.Name,
@@ -224,10 +224,11 @@ func ListModels(models []*gallery.GalleryModel, installing *xsync.SyncedMap[stri
224224
elem.Raw(StartProgressBar(installing.Get(galleryID), "0", "Installing")),
225225
), // Otherwise, show install button (if not installed) or display "Installed"
226226
elem.If(m.Installed,
227-
elem.Node(elem.Div(
228-
attrs.Props{},
229-
span("Installed"), deleteButton(m),
230-
)),
227+
//elem.Node(elem.Div(
228+
// attrs.Props{},
229+
// span("Installed"), deleteButton(m),
230+
// )),
231+
deleteButton(m),
231232
installButton(m),
232233
),
233234
),

pkg/gallery/gallery.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gallery
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -193,6 +194,7 @@ func DeleteModelFromSystem(basePath string, name string, additionalFiles []strin
193194

194195
galleryFile := filepath.Join(basePath, galleryFileName(name))
195196

197+
var err error
196198
// Delete all the files associated to the model
197199
// read the model config
198200
galleryconfig, err := ReadConfigFile(galleryFile)
@@ -205,20 +207,26 @@ func DeleteModelFromSystem(basePath string, name string, additionalFiles []strin
205207
for _, f := range galleryconfig.Files {
206208
fullPath := filepath.Join(basePath, f.Filename)
207209
log.Debug().Msgf("Removing file %s", fullPath)
208-
if err := os.Remove(fullPath); err != nil {
209-
return fmt.Errorf("failed to remove file %s: %w", f.Filename, err)
210+
if e := os.Remove(fullPath); e != nil {
211+
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", f.Filename, e))
210212
}
211213
}
212214
}
213215

214216
for _, f := range additionalFiles {
215217
fullPath := filepath.Join(filepath.Join(basePath, f))
216218
log.Debug().Msgf("Removing additional file %s", fullPath)
217-
if err := os.Remove(fullPath); err != nil {
218-
return fmt.Errorf("failed to remove file %s: %w", f, err)
219+
if e := os.Remove(fullPath); e != nil {
220+
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", f, e))
219221
}
220222
}
221223

224+
log.Debug().Msgf("Removing model config file %s", configFile)
225+
222226
// Delete the model config file
223-
return os.RemoveAll(configFile)
227+
if e := os.Remove(configFile); e != nil {
228+
err = errors.Join(err, fmt.Errorf("failed to remove file %s: %w", configFile, e))
229+
}
230+
231+
return err
224232
}

0 commit comments

Comments
 (0)