Skip to content

Commit efaf137

Browse files
committed
Fail if no importer matches
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent cedeff1 commit efaf137

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

core/gallery/importers/importers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package importers
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"os"
67
"strings"
78

@@ -101,14 +102,19 @@ func DiscoverModelConfig(uri string, preferences json.RawMessage) (gallery.Model
101102
Preferences: preferences,
102103
}
103104

105+
importerMatched := false
104106
for _, importer := range defaultImporters {
105107
if importer.Match(details) {
108+
importerMatched = true
106109
modelConfig, err = importer.Import(details)
107110
if err != nil {
108111
continue
109112
}
110113
break
111114
}
112115
}
116+
if !importerMatched {
117+
return gallery.ModelConfig{}, fmt.Errorf("no importer matched for %s", uri)
118+
}
113119
return modelConfig, nil
114120
}

core/gallery/importers/llama-cpp.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/mudler/LocalAI/core/schema"
1212
"github.com/mudler/LocalAI/pkg/downloader"
1313
"github.com/mudler/LocalAI/pkg/functions"
14+
"github.com/rs/zerolog/log"
1415
"go.yaml.in/yaml/v2"
1516
)
1617

@@ -21,12 +22,18 @@ type LlamaCPPImporter struct{}
2122
func (i *LlamaCPPImporter) Match(details Details) bool {
2223
preferences, err := details.Preferences.MarshalJSON()
2324
if err != nil {
25+
log.Error().Err(err).Msg("failed to marshal preferences")
2426
return false
2527
}
28+
2629
preferencesMap := make(map[string]any)
27-
err = json.Unmarshal(preferences, &preferencesMap)
28-
if err != nil {
29-
return false
30+
31+
if len(preferences) > 0 {
32+
err = json.Unmarshal(preferences, &preferencesMap)
33+
if err != nil {
34+
log.Error().Err(err).Msg("failed to unmarshal preferences")
35+
return false
36+
}
3037
}
3138

3239
uri := downloader.URI(details.URI)
@@ -39,10 +46,6 @@ func (i *LlamaCPPImporter) Match(details Details) bool {
3946
return true
4047
}
4148

42-
if uri.LooksLikeURL() && strings.HasSuffix(details.URI, ".gguf") {
43-
return true
44-
}
45-
4649
if uri.LooksLikeOCI() {
4750
return true
4851
}
@@ -59,6 +62,9 @@ func (i *LlamaCPPImporter) Match(details Details) bool {
5962
}
6063

6164
func (i *LlamaCPPImporter) Import(details Details) (gallery.ModelConfig, error) {
65+
66+
log.Debug().Str("uri", details.URI).Msg("llama.cpp importer matched")
67+
6268
preferences, err := details.Preferences.MarshalJSON()
6369
if err != nil {
6470
return gallery.ModelConfig{}, err

0 commit comments

Comments
 (0)