mirror of
https://github.com/mudler/LocalAI.git
synced 2025-12-31 06:29:55 -06:00
- Add a system backend path - Refactor and consolidate system information in system state - Use system state in all the components to figure out the system paths to used whenever needed - Refactor BackendConfig -> ModelConfig. This was otherway misleading as now we do have a backend configuration which is not the model config. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package system
|
|
|
|
import (
|
|
"github.com/jaypipes/ghw/pkg/gpu"
|
|
"github.com/mudler/LocalAI/pkg/xsysinfo"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type Backend struct {
|
|
BackendsPath string
|
|
BackendsSystemPath string
|
|
}
|
|
|
|
type Model struct {
|
|
ModelsPath string
|
|
}
|
|
|
|
type SystemState struct {
|
|
GPUVendor string
|
|
Backend Backend
|
|
Model Model
|
|
gpus []*gpu.GraphicsCard
|
|
VRAM uint64
|
|
}
|
|
|
|
type SystemStateOptions func(*SystemState)
|
|
|
|
func WithBackendPath(path string) SystemStateOptions {
|
|
return func(s *SystemState) {
|
|
s.Backend.BackendsPath = path
|
|
}
|
|
}
|
|
|
|
func WithBackendSystemPath(path string) SystemStateOptions {
|
|
return func(s *SystemState) {
|
|
s.Backend.BackendsSystemPath = path
|
|
}
|
|
}
|
|
|
|
func WithModelPath(path string) SystemStateOptions {
|
|
return func(s *SystemState) {
|
|
s.Model.ModelsPath = path
|
|
}
|
|
}
|
|
|
|
func GetSystemState(opts ...SystemStateOptions) (*SystemState, error) {
|
|
state := &SystemState{}
|
|
for _, opt := range opts {
|
|
opt(state)
|
|
}
|
|
|
|
// Detection is best-effort here, we don't want to fail if it fails
|
|
state.gpus, _ = xsysinfo.GPUs()
|
|
log.Debug().Any("gpus", state.gpus).Msg("GPUs")
|
|
state.GPUVendor, _ = detectGPUVendor(state.gpus)
|
|
log.Debug().Str("gpuVendor", state.GPUVendor).Msg("GPU vendor")
|
|
state.VRAM, _ = xsysinfo.TotalAvailableVRAM()
|
|
log.Debug().Any("vram", state.VRAM).Msg("Total available VRAM")
|
|
|
|
return state, nil
|
|
}
|