diff --git a/pkg/system/capabilities.go b/pkg/system/capabilities.go index 034f1d011..9e74a2e8b 100644 --- a/pkg/system/capabilities.go +++ b/pkg/system/capabilities.go @@ -63,6 +63,17 @@ func (s *SystemState) CapabilityFilterDisabled() bool { return s.getSystemCapabilities() == disableCapability } +// ReportedCapability returns the raw detected capability string (e.g. "metal", +// "nvidia-cuda-12", "default") with no map-membership fallback applied. +// +// Why this exists alongside Capability: Capability resolves against a caller +// supplied map and falls back to "default" then "cpu" when the detected value +// is absent. Model meta entries express fallback through candidate ordering +// instead, so they need the undecorated value. +func (s *SystemState) ReportedCapability() string { + return s.getSystemCapabilities() +} + func (s *SystemState) Capability(capMap map[string]string) string { reportedCapability := s.getSystemCapabilities() diff --git a/pkg/system/capabilities_test.go b/pkg/system/capabilities_test.go index 1bb13b647..117e3ffdb 100644 --- a/pkg/system/capabilities_test.go +++ b/pkg/system/capabilities_test.go @@ -164,3 +164,28 @@ var _ = Describe("CapabilityFilterDisabled", func() { Expect(s.IsBackendCompatible("cpu-whisperx", "quay.io/cpu")).To(BeTrue()) }) }) + +var _ = Describe("ReportedCapability", func() { + var previous string + + BeforeEach(func() { + previous = os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY") + }) + + AfterEach(func() { + Expect(os.Setenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY", previous)).To(Succeed()) + }) + + It("returns the forced capability verbatim without map fallback", func() { + Expect(os.Setenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY", "nvidia-cuda-12")).To(Succeed()) + state := &SystemState{} + Expect(state.ReportedCapability()).To(Equal("nvidia-cuda-12")) + }) + + It("does not fall back to default when the capability is unusual", func() { + Expect(os.Setenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY", "metal")).To(Succeed()) + state := &SystemState{} + Expect(state.ReportedCapability()).To(Equal("metal")) + Expect(state.ReportedCapability()).NotTo(Equal("default")) + }) +})