mirror of
https://github.com/mudler/LocalAI.git
synced 2026-01-07 11:10:11 -06:00
fix(backends gallery): trim string when reading cap from file (#5909)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
committed by
GitHub
parent
ee625fc34e
commit
f0b47cfe6a
@@ -3,6 +3,7 @@ package gallery
|
||||
import (
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/pkg/system"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// BackendMetadata represents the metadata stored in a JSON file for each installed backend
|
||||
@@ -33,9 +34,11 @@ func (backend *GalleryBackend) FindBestBackendFromMeta(systemState *system.Syste
|
||||
|
||||
realBackend := backend.CapabilitiesMap[systemState.Capability(backend.CapabilitiesMap)]
|
||||
if realBackend == "" {
|
||||
log.Debug().Str("backend", backend.Name).Str("reportedCapability", systemState.Capability(backend.CapabilitiesMap)).Msg("No backend found for reported capability")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug().Str("backend", backend.Name).Str("reportedCapability", systemState.Capability(backend.CapabilitiesMap)).Msg("Found backend for reported capability")
|
||||
return backends.FindByName(realBackend)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ func (g *GalleryService) backendHandler(op *GalleryOp[gallery.GalleryBackend], s
|
||||
g.modelLoader.DeleteExternalBackend(op.GalleryElementName)
|
||||
} else {
|
||||
log.Warn().Msgf("installing backend %s", op.GalleryElementName)
|
||||
log.Debug().Msgf("backend galleries: %v", g.appConfig.BackendGalleries)
|
||||
err = gallery.InstallBackendFromGallery(g.appConfig.BackendGalleries, systemState, op.GalleryElementName, g.appConfig.BackendsPath, progressCallback, true)
|
||||
if err == nil {
|
||||
err = gallery.RegisterBackends(g.appConfig.BackendsPath, g.modelLoader)
|
||||
|
||||
@@ -25,20 +25,24 @@ func (s *SystemState) Capability(capMap map[string]string) string {
|
||||
|
||||
// Check if the reported capability is in the map
|
||||
if _, exists := capMap[reportedCapability]; exists {
|
||||
log.Debug().Str("reportedCapability", reportedCapability).Any("capMap", capMap).Msg("Using reported capability")
|
||||
return reportedCapability
|
||||
}
|
||||
|
||||
log.Debug().Str("reportedCapability", reportedCapability).Any("capMap", capMap).Msg("The requested capability was not found, using default capability")
|
||||
// Otherwise, return the default capability (catch-all)
|
||||
return defaultCapability
|
||||
}
|
||||
|
||||
func (s *SystemState) getSystemCapabilities() string {
|
||||
if os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY") != "" {
|
||||
log.Debug().Str("LOCALAI_FORCE_META_BACKEND_CAPABILITY", os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY")).Msg("Using forced capability")
|
||||
return os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY")
|
||||
}
|
||||
|
||||
capabilityRunFile := "/run/localai/capability"
|
||||
if os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE") != "" {
|
||||
log.Debug().Str("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE", os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE")).Msg("Using forced capability run file")
|
||||
capabilityRunFile = os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE")
|
||||
}
|
||||
|
||||
@@ -48,31 +52,37 @@ func (s *SystemState) getSystemCapabilities() string {
|
||||
if _, err := os.Stat(capabilityRunFile); err == nil {
|
||||
capability, err := os.ReadFile(capabilityRunFile)
|
||||
if err == nil {
|
||||
return string(capability)
|
||||
log.Debug().Str("capability", string(capability)).Msg("Using capability from run file")
|
||||
return strings.Trim(strings.TrimSpace(string(capability)), "\n")
|
||||
}
|
||||
}
|
||||
|
||||
// If we are on mac and arm64, we will return metal
|
||||
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
|
||||
log.Debug().Msg("Using metal capability")
|
||||
return metal
|
||||
}
|
||||
|
||||
// If we are on mac and x86, we will return darwin-x86
|
||||
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
|
||||
log.Debug().Msg("Using darwin-x86 capability")
|
||||
return darwinX86
|
||||
}
|
||||
|
||||
// If arm64 on linux and a nvidia gpu is detected, we will return nvidia-l4t
|
||||
if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
|
||||
if s.GPUVendor == "nvidia" {
|
||||
log.Debug().Msg("Using nvidia-l4t capability")
|
||||
return nvidiaL4T
|
||||
}
|
||||
}
|
||||
|
||||
if s.GPUVendor == "" {
|
||||
log.Debug().Msg("Using default capability")
|
||||
return defaultCapability
|
||||
}
|
||||
|
||||
log.Debug().Str("GPUVendor", s.GPUVendor).Msg("Using GPU vendor capability")
|
||||
return s.GPUVendor
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user