Skip to content

Commit bbbb28e

Browse files
authored
fix(models): unify usecases identifications (mudler#4914)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 3bf2e9d commit bbbb28e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

core/config/backend_config.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,15 @@ func (c *BackendConfig) UnmarshalYAML(value *yaml.Node) error {
222222
return err
223223
}
224224
*c = BackendConfig(aux)
225+
225226
c.KnownUsecases = GetUsecasesFromYAML(c.KnownUsecaseStrings)
227+
// Make sure the usecases are valid, we rewrite with what we identified
228+
c.KnownUsecaseStrings = []string{}
229+
for k, usecase := range GetAllBackendConfigUsecases() {
230+
if c.HasUsecases(usecase) {
231+
c.KnownUsecaseStrings = append(c.KnownUsecaseStrings, k)
232+
}
233+
}
226234
return nil
227235
}
228236

@@ -410,15 +418,6 @@ func (cfg *BackendConfig) SetDefaults(opts ...ConfigLoaderOption) {
410418
cfg.Debug = &trueV
411419
}
412420

413-
if len(cfg.KnownUsecaseStrings) == 0 {
414-
// Infer use case if not provided
415-
for k, usecase := range GetAllBackendConfigUsecases() {
416-
if cfg.HasUsecases(usecase) {
417-
cfg.KnownUsecaseStrings = append(cfg.KnownUsecaseStrings, k)
418-
}
419-
}
420-
}
421-
422421
guessDefaultsFromFile(cfg, lo.modelPath)
423422
}
424423

@@ -491,14 +490,18 @@ func GetAllBackendConfigUsecases() map[string]BackendConfigUsecases {
491490
}
492491
}
493492

493+
func stringToFlag(s string) string {
494+
return "FLAG_" + strings.ToUpper(s)
495+
}
496+
494497
func GetUsecasesFromYAML(input []string) *BackendConfigUsecases {
495498
if len(input) == 0 {
496499
return nil
497500
}
498501
result := FLAG_ANY
499502
flags := GetAllBackendConfigUsecases()
500503
for _, str := range input {
501-
flag, exists := flags["FLAG_"+strings.ToUpper(str)]
504+
flag, exists := flags[stringToFlag(str)]
502505
if exists {
503506
result |= flag
504507
}

0 commit comments

Comments
 (0)