* add llamacpp plugin * Refactor llamacpp plugin * add utils plugin * remove utils folder * add hardware implementation * add utils folder + move utils function * organize cargo files * refactor utils src * refactor util * apply fmt * fmt * Update gguf + reformat * add permission for gguf commands * fix cargo test windows * revert yarn lock * remove cargo.lock for hardware plugin * ignore cargo.lock file * Fix hardware invoke + refactor hardware + refactor tests, constants * use api wrapper in extension to invoke hardware call + api wrapper build integration * add newline at EOF (per Akarshan) * add vi mock for getSystemInfo
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { HardwareData, SystemUsage } from '@/hooks/useHardware'
|
|
import { invoke } from '@tauri-apps/api/core'
|
|
|
|
// Device list interface for llamacpp extension
|
|
export interface DeviceList {
|
|
id: string
|
|
name: string
|
|
mem: number
|
|
free: number
|
|
activated: boolean
|
|
}
|
|
|
|
/**
|
|
* Get hardware information from the HardwareManagementExtension.
|
|
* @returns {Promise<HardwareInfo>} A promise that resolves to the hardware information.
|
|
*/
|
|
export const getHardwareInfo = async () => {
|
|
return invoke('plugin:hardware|get_system_info') as Promise<HardwareData>
|
|
}
|
|
|
|
/**
|
|
* Get hardware information from the HardwareManagementExtension.
|
|
* @returns {Promise<HardwareInfo>} A promise that resolves to the hardware information.
|
|
*/
|
|
export const getSystemUsage = async () => {
|
|
return invoke('plugin:hardware|get_system_usage') as Promise<SystemUsage>
|
|
}
|
|
|
|
/**
|
|
* Get devices from the llamacpp extension.
|
|
* @returns {Promise<DeviceList[]>} A promise that resolves to the list of available devices.
|
|
*/
|
|
export const getLlamacppDevices = async (): Promise<DeviceList[]> => {
|
|
const extensionManager = window.core.extensionManager
|
|
const llamacppExtension = extensionManager.getByName(
|
|
'@janhq/llamacpp-extension'
|
|
)
|
|
|
|
if (!llamacppExtension) {
|
|
throw new Error('llamacpp extension not found')
|
|
}
|
|
|
|
return llamacppExtension.getDevices()
|
|
}
|
|
|
|
/**
|
|
* Set gpus activate
|
|
* @returns A Promise that resolves set gpus activate.
|
|
*/
|
|
export const setActiveGpus = async (data: { gpus: number[] }) => {
|
|
// TODO: llama.cpp extension should handle this
|
|
console.log(data)
|
|
}
|