SPB Git

spb/zyquo-mlx Public MIT

The local MLX foundry for your Mac — run, fine-tune, quantize, and ship models. Nothing leaves your machine.

Swift 93.4% Python 3.8% Makefile 2.2% Shell 0.5%
1.9 KB · 59 lines swift
Raw Blame History
1//2//  PersistenceService.swift3//  Zyquo MLX4//5//  Author: Simon-Pierre Boucher6//  Mail: contact@spboucher.ai7//89import Foundation1011/// Canonical data locations (charter naming conventions) and small JSON12/// persistence helpers used across stores.13enum PersistenceService {1415    /// `~/Library/Application Support/ZyquoMLX/`16    static var appSupportDirectory: URL {17        FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]18            .appendingPathComponent("ZyquoMLX", isDirectory: true)19    }2021    static var modelsDirectory: URL {22        appSupportDirectory.appendingPathComponent("Models", isDirectory: true)23    }2425    static var datasetsDirectory: URL {26        appSupportDirectory.appendingPathComponent("Datasets", isDirectory: true)27    }2829    static var runsDirectory: URL {30        appSupportDirectory.appendingPathComponent("Runs", isDirectory: true)31    }3233    static var pythonDirectory: URL {34        appSupportDirectory.appendingPathComponent("py", isDirectory: true)35    }3637    /// Create all canonical directories if missing (first launch).38    static func ensureDirectories() throws {39        let fm = FileManager.default40        for url in [appSupportDirectory, modelsDirectory, datasetsDirectory, runsDirectory] {41            try fm.createDirectory(at: url, withIntermediateDirectories: true)42        }43    }4445    static func loadJSON<T: Decodable>(_ type: T.Type, from url: URL) throws -> T {46        let data = try Data(contentsOf: url)47        let decoder = JSONDecoder()48        decoder.dateDecodingStrategy = .iso860149        return try decoder.decode(type, from: data)50    }5152    static func saveJSON<T: Encodable>(_ value: T, to url: URL) throws {53        let encoder = JSONEncoder()54        encoder.dateEncodingStrategy = .iso860155        encoder.outputFormatting = [.prettyPrinted, .sortedKeys]56        try encoder.encode(value).write(to: url, options: .atomic)57    }58}59