@@ -2,14 +2,14 @@ package model
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"os"
7
8
"path/filepath"
8
9
"strings"
9
10
"time"
10
11
11
12
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
12
- "github.com/hashicorp/go-multierror"
13
13
"github.com/phayes/freeport"
14
14
"github.com/rs/zerolog/log"
15
15
)
@@ -39,16 +39,22 @@ const (
39
39
LocalStoreBackend = "local-store"
40
40
)
41
41
42
- var AutoLoadBackends []string = []string {
43
- LLamaCPP ,
44
- LlamaGGML ,
45
- Gpt4All ,
46
- BertEmbeddingsBackend ,
47
- RwkvBackend ,
48
- WhisperBackend ,
49
- StableDiffusionBackend ,
50
- TinyDreamBackend ,
51
- PiperBackend ,
42
+ func backendPath (assetDir , backend string ) string {
43
+ return filepath .Join (assetDir , "backend-assets" , "grpc" , backend )
44
+ }
45
+
46
+ func bakends (assetDir string ) ([]string , error ) {
47
+ entry , err := os .ReadDir (backendPath (assetDir , "" ))
48
+ if err != nil {
49
+ return nil , err
50
+ }
51
+ var backends []string
52
+ for _ , e := range entry {
53
+ if ! e .IsDir () {
54
+ backends = append (backends , e .Name ())
55
+ }
56
+ }
57
+ return backends , nil
52
58
}
53
59
54
60
// starts the grpcModelProcess for the backend, and returns a grpc client
@@ -99,7 +105,7 @@ func (ml *ModelLoader) grpcModel(backend string, o *Options) func(string, string
99
105
client = ModelAddress (uri )
100
106
}
101
107
} else {
102
- grpcProcess := filepath . Join (o .assetDir , "backend-assets" , "grpc" , backend )
108
+ grpcProcess := backendPath (o .assetDir , backend )
103
109
// Check if the file exists
104
110
if _ , err := os .Stat (grpcProcess ); os .IsNotExist (err ) {
105
111
return "" , fmt .Errorf ("grpc process not found: %s. some backends(stablediffusion, tts) require LocalAI compiled with GO_TAGS" , grpcProcess )
@@ -243,7 +249,11 @@ func (ml *ModelLoader) GreedyLoader(opts ...Option) (grpc.Backend, error) {
243
249
244
250
// autoload also external backends
245
251
allBackendsToAutoLoad := []string {}
246
- allBackendsToAutoLoad = append (allBackendsToAutoLoad , AutoLoadBackends ... )
252
+ autoLoadBackends , err := bakends (o .assetDir )
253
+ if err != nil {
254
+ return nil , err
255
+ }
256
+ allBackendsToAutoLoad = append (allBackendsToAutoLoad , autoLoadBackends ... )
247
257
for _ , b := range o .externalBackends {
248
258
allBackendsToAutoLoad = append (allBackendsToAutoLoad , b )
249
259
}
@@ -271,10 +281,10 @@ func (ml *ModelLoader) GreedyLoader(opts ...Option) (grpc.Backend, error) {
271
281
log .Info ().Msgf ("[%s] Loads OK" , b )
272
282
return model , nil
273
283
} else if modelerr != nil {
274
- err = multierror . Append (err , modelerr )
284
+ err = errors . Join (err , modelerr )
275
285
log .Info ().Msgf ("[%s] Fails: %s" , b , modelerr .Error ())
276
286
} else if model == nil {
277
- err = multierror . Append (err , fmt .Errorf ("backend returned no usable model" ))
287
+ err = errors . Join (err , fmt .Errorf ("backend returned no usable model" ))
278
288
log .Info ().Msgf ("[%s] Fails: %s" , b , "backend returned no usable model" )
279
289
}
280
290
}
0 commit comments