Dolphin3.0-CoreML / examples /ios /DolphinCoreMLTestApp /Sources /SystemTools /SystemResourceSnapshotProvider.swift
ales27pm's picture
Add autonomous on-device iOS assistant
7b2dfc5 verified
Raw
History Blame Contribute Delete
761 Bytes
@preconcurrency import Darwin
import Foundation
struct SystemResourceSnapshotProvider: Sendable {
func snapshot() -> AssistantResourceSnapshot {
let processInfo = ProcessInfo.processInfo
return AssistantResourceSnapshot(
thermalLevel: thermalLevel(processInfo.thermalState),
lowPowerModeEnabled: processInfo.isLowPowerModeEnabled,
availableMemoryBytes: UInt64(os_proc_available_memory())
)
}
private func thermalLevel(
_ state: ProcessInfo.ThermalState
) -> AssistantThermalLevel {
switch state {
case .nominal:
return .nominal
case .fair:
return .fair
case .serious:
return .serious
case .critical:
return .critical
@unknown default:
return .unknown
}
}
}