Skip to content

Commit a35a701

Browse files
authored
feat(backends): install from local path (#5962)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 3d8ec72 commit a35a701

File tree

5 files changed

+43
-66
lines changed

5 files changed

+43
-66
lines changed

core/gallery/backends.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/mudler/LocalAI/pkg/downloader"
1212
"github.com/mudler/LocalAI/pkg/model"
1313
"github.com/mudler/LocalAI/pkg/system"
14+
cp "github.com/otiai10/copy"
1415
"github.com/rs/zerolog/log"
1516
)
1617

@@ -145,18 +146,27 @@ func InstallBackend(basePath string, config *GalleryBackend, downloadStatus func
145146
}
146147

147148
uri := downloader.URI(config.URI)
148-
if err := uri.DownloadFile(backendPath, "", 1, 1, downloadStatus); err != nil {
149-
success := false
150-
// Try to download from mirrors
151-
for _, mirror := range config.Mirrors {
152-
if err := downloader.URI(mirror).DownloadFile(backendPath, "", 1, 1, downloadStatus); err == nil {
153-
success = true
154-
break
155-
}
149+
// Check if it is a directory
150+
if uri.LooksLikeDir() {
151+
// It is a directory, we just copy it over in the backend folder
152+
if err := cp.Copy(config.URI, backendPath); err != nil {
153+
return fmt.Errorf("failed copying: %w", err)
156154
}
155+
} else {
156+
uri := downloader.URI(config.URI)
157+
if err := uri.DownloadFile(backendPath, "", 1, 1, downloadStatus); err != nil {
158+
success := false
159+
// Try to download from mirrors
160+
for _, mirror := range config.Mirrors {
161+
if err := downloader.URI(mirror).DownloadFile(backendPath, "", 1, 1, downloadStatus); err == nil {
162+
success = true
163+
break
164+
}
165+
}
157166

158-
if !success {
159-
return fmt.Errorf("failed to download backend %q: %v", config.URI, err)
167+
if !success {
168+
return fmt.Errorf("failed to download backend %q: %v", config.URI, err)
169+
}
160170
}
161171
}
162172

core/startup/backend_preload.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ func InstallExternalBackends(galleries []config.Gallery, backendPath string, dow
2222
for _, backend := range backends {
2323
uri := downloader.URI(backend)
2424
switch {
25+
case uri.LooksLikeDir():
26+
name := filepath.Base(backend)
27+
log.Info().Str("backend", backend).Str("name", name).Msg("Installing backend from path")
28+
if err := gallery.InstallBackend(backendPath, &gallery.GalleryBackend{
29+
Metadata: gallery.Metadata{
30+
Name: name,
31+
},
32+
URI: backend,
33+
}, downloadStatus); err != nil {
34+
errs = errors.Join(err, fmt.Errorf("error installing backend %s", backend))
35+
}
2536
case uri.LooksLikeOCI():
2637
name, err := uri.FilenameFromUrl()
2738
if err != nil {

go.mod

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ require (
3737
github.com/nikolalohinski/gonja/v2 v2.3.2
3838
github.com/onsi/ginkgo/v2 v2.22.2
3939
github.com/onsi/gomega v1.36.2
40+
github.com/otiai10/copy v1.14.1
4041
github.com/otiai10/openaigo v1.7.0
4142
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
4243
github.com/prometheus/client_golang v1.21.0
@@ -65,15 +66,12 @@ require (
6566
require (
6667
github.com/containerd/platforms v0.2.1 // indirect
6768
github.com/cpuguy83/dockercfg v0.3.2 // indirect
68-
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
6969
github.com/distribution/reference v0.6.0 // indirect
7070
github.com/dustin/go-humanize v1.0.1 // indirect
7171
github.com/fasthttp/websocket v1.5.8 // indirect
7272
github.com/felixge/httpsnoop v1.0.4 // indirect
7373
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
7474
github.com/json-iterator/go v1.1.12 // indirect
75-
github.com/labstack/echo/v4 v4.13.3 // indirect
76-
github.com/labstack/gommon v0.4.2 // indirect
7775
github.com/libp2p/go-yamux/v5 v5.0.0 // indirect
7876
github.com/magiconair/properties v1.8.7 // indirect
7977
github.com/moby/docker-image-spec v1.3.1 // indirect
@@ -83,14 +81,13 @@ require (
8381
github.com/modern-go/reflect2 v1.0.2 // indirect
8482
github.com/morikuni/aec v1.0.0 // indirect
8583
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
84+
github.com/otiai10/mint v1.6.3 // indirect
8685
github.com/pion/datachannel v1.5.10 // indirect
8786
github.com/pion/dtls/v2 v2.2.12 // indirect
8887
github.com/pion/dtls/v3 v3.0.4 // indirect
89-
github.com/pion/ice/v2 v2.3.37 // indirect
9088
github.com/pion/ice/v4 v4.0.6 // indirect
9189
github.com/pion/interceptor v0.1.37 // indirect
9290
github.com/pion/logging v0.2.3 // indirect
93-
github.com/pion/mdns v0.0.12 // indirect
9491
github.com/pion/mdns/v2 v2.0.7 // indirect
9592
github.com/pion/randutil v0.1.0 // indirect
9693
github.com/pion/rtcp v1.2.15 // indirect
@@ -102,17 +99,12 @@ require (
10299
github.com/pion/stun/v3 v3.0.0 // indirect
103100
github.com/pion/transport/v2 v2.2.10 // indirect
104101
github.com/pion/transport/v3 v3.0.7 // indirect
105-
github.com/pion/turn/v2 v2.1.6 // indirect
106102
github.com/pion/turn/v4 v4.0.0 // indirect
107103
github.com/pion/webrtc/v4 v4.0.9 // indirect
108104
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529 // indirect
109-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
110105
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect
111106
github.com/shirou/gopsutil/v4 v4.24.7 // indirect
112-
github.com/urfave/cli/v2 v2.27.5 // indirect
113-
github.com/valyala/fasttemplate v1.2.2 // indirect
114107
github.com/wlynxg/anet v0.0.5 // indirect
115-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
116108
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
117109
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
118110
go.uber.org/mock v0.5.0 // indirect
@@ -213,7 +205,6 @@ require (
213205
github.com/libp2p/go-nat v0.2.0 // indirect
214206
github.com/libp2p/go-netroute v0.2.2 // indirect
215207
github.com/libp2p/go-reuseport v0.4.0 // indirect
216-
github.com/libp2p/go-yamux/v4 v4.0.2 // indirect
217208
github.com/libp2p/zeroconf/v2 v2.2.0 // indirect
218209
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
219210
github.com/lufia/plan9stats v0.0.0-20240819163618-b1d8f4d146e7 // indirect

0 commit comments

Comments
 (0)