mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-30 09:57:57 -04:00
refactor(system): drop duplicate capability accessor, cover DetectedCapability
ReportedCapability was added with a body identical to the existing DetectedCapability. Keep one accessor and move the specs onto it, since DetectedCapability had no direct coverage of its no-fallback behavior. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
@@ -63,17 +63,6 @@ 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()
|
||||
|
||||
@@ -217,8 +206,14 @@ func (s *SystemState) BackendPreferenceTokens() []string {
|
||||
}
|
||||
}
|
||||
|
||||
// DetectedCapability returns the detected system capability string.
|
||||
// DetectedCapability returns the raw detected capability string (e.g. "metal",
|
||||
// "nvidia-cuda-12", "default") with no map-membership fallback applied.
|
||||
// This can be used by the UI to display what capability was detected.
|
||||
//
|
||||
// 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 from that map. Callers that express fallback themselves, such as
|
||||
// model meta entries ordering their own candidates, need the undecorated value.
|
||||
func (s *SystemState) DetectedCapability() string {
|
||||
return s.getSystemCapabilities()
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ var _ = Describe("CapabilityFilterDisabled", func() {
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("ReportedCapability", func() {
|
||||
var _ = Describe("DetectedCapability", func() {
|
||||
var previous string
|
||||
|
||||
BeforeEach(func() {
|
||||
@@ -179,13 +179,13 @@ var _ = Describe("ReportedCapability", func() {
|
||||
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"))
|
||||
Expect(state.DetectedCapability()).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"))
|
||||
Expect(state.DetectedCapability()).To(Equal("metal"))
|
||||
Expect(state.DetectedCapability()).NotTo(Equal("default"))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user