File size: 1,181 Bytes
0f07ba7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
package system
import (
"github.com/mudler/LocalAI/pkg/xsysinfo"
"github.com/mudler/xlog"
)
type Backend struct {
BackendsPath string
BackendsSystemPath string
}
type Model struct {
ModelsPath string
}
type SystemState struct {
GPUVendor string
Backend Backend
Model Model
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.GPUVendor, _ = xsysinfo.DetectGPUVendor()
xlog.Debug("GPU vendor", "gpuVendor", state.GPUVendor)
state.VRAM, _ = xsysinfo.TotalAvailableVRAM()
xlog.Debug("Total available VRAM", "vram", state.VRAM)
return state, nil
}
|