import type { Storage, StorageValue } from 'unstorage' import type { EvaluationResult } from './types' import * as path from 'node:path' import { createStorage } from 'unstorage' // @ts-expect-error: No types available import fsDriver from 'unstorage/drivers/fs' import { BENCHMARKS_DIR } from './constants' /** * Storage instance for model results * * @remarks * Stores results in: `benchmarks/results/accuracy/models/` */ export const resultsStorage: Storage = createStorage({ driver: fsDriver({ base: path.join(BENCHMARKS_DIR, 'results', 'accuracy', 'models'), }), }) export async function loadModelResults(modelId: string): Promise { const data = await resultsStorage.getItem(modelId) return data ?? undefined } export async function saveModelResults(modelId: string, results: EvaluationResult[]): Promise { await resultsStorage.setItem(modelId, results) } export async function getAllModelResults(): Promise> { const keys = await resultsStorage.getKeys() const results: Record = {} await Promise.all( keys.map(async (modelId) => { const data = await resultsStorage.getItem(modelId) if (data) results[modelId] = data }), ) return results } export async function hasModelResults(modelId: string): Promise { return await resultsStorage.hasItem(modelId) }