MCPcopy
hub / github.com/xpf0000/FlyEnv / fetchHardware

Function fetchHardware

src/render/components/Ollama/models/all/setup.ts:86–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84 }
85
86 const fetchHardware = async () => {
87 try {
88 const res: any = await new Promise((resolve, reject) => {
89 IPC.send('app-fork:ollama', 'pcReport').then((key: string, res: any) => {
90 IPC.off(key)
91 if (res?.data) resolve(res.data)
92 else reject(new Error('No data'))
93 })
94 })
95
96 const toArr = (v: any) => (Array.isArray(v) ? v : v ? [v] : [])
97
98 const mods = toArr(res?.memory)
99 const totalRam = mods.reduce((s: number, m: any) => s + Number(m?.Capacity || 0), 0)
100 hardware.ramGB = totalRam ? Math.round((totalRam / 1024 / 1024 / 1024) * 100) / 100 : 0
101
102 let maxVram = 0
103 const nvidia = toArr(res?.nvidia)
104 nvidia.forEach((row: any) => {
105 const gb = Number(row?.MemoryTotalMiB || 0) / 1024
106 if (gb > maxVram) maxVram = gb
107 })
108 if (maxVram === 0) {
109 const gpus = toArr(res?.gpu)
110 gpus.forEach((g: any) => {
111 const gb = Number(g?.AdapterRAM || 0) / 1024 / 1024 / 1024
112 if (gb > maxVram) maxVram = gb
113 })
114 }
115 hardware.vramGB = maxVram ? Math.round(maxVram * 100) / 100 : 0
116 hardware.loaded = true
117 } catch {
118 hardware.loaded = false
119 }
120
121 console.log('hardware: ', hardware)
122 }
123
124 const getModelSizeColor = (sizeText?: string): 'success' | 'warning' | 'danger' | undefined => {
125 if (!hardware.loaded) return undefined

Callers 1

SetupFunction · 0.85

Calls 6

resolveFunction · 0.85
toArrFunction · 0.85
offMethod · 0.80
thenMethod · 0.45
sendMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected