From 5ff42abca5398226317f5f417f0e27ac8422e590 Mon Sep 17 00:00:00 2001 From: Georgy Date: Thu, 27 Aug 2026 23:32:19 +0300 Subject: [PATCH] fix: show precise units for small model downloads --- .../local-llm.models.test.ts | 13 ++++++++++++- .../local-llm-playground/local-llm.models.ts | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/tools/local-llm-playground/local-llm.models.test.ts b/src/tools/local-llm-playground/local-llm.models.test.ts index 879bc311b2..124ce56e12 100644 --- a/src/tools/local-llm-playground/local-llm.models.test.ts +++ b/src/tools/local-llm-playground/local-llm.models.test.ts @@ -1,6 +1,10 @@ import { describe, expect, it } from 'vitest'; import modelAssets from './local-llm-model-assets.json'; -import { LOCAL_LLM_MODELS, getLocalLlmModelAssetBasePath } from './local-llm.models'; +import { + LOCAL_LLM_MODELS, + formatLocalLlmBytes, + getLocalLlmModelAssetBasePath, +} from './local-llm.models'; describe('local LLM model assets', () => { it('keeps runtime models aligned with the pinned same-origin mirror catalog', () => { @@ -20,4 +24,11 @@ describe('local LLM model assets', () => { expect(model.files.some(file => /vision_encoder|fp16|quantized/u.test(file))).toBe(false); } }); + + it('uses byte-sized units for small download progress values', () => { + expect(formatLocalLlmBytes(0)).toBe('0 B'); + expect(formatLocalLlmBytes(857)).toBe('857 B'); + expect(formatLocalLlmBytes(1.5 * 1024)).toBe('1.5 KiB'); + expect(formatLocalLlmBytes(155 * 1024 ** 2)).toBe('155 MiB'); + }); }); diff --git a/src/tools/local-llm-playground/local-llm.models.ts b/src/tools/local-llm-playground/local-llm.models.ts index 4aa3c68cf6..53e181a122 100644 --- a/src/tools/local-llm-playground/local-llm.models.ts +++ b/src/tools/local-llm-playground/local-llm.models.ts @@ -11,7 +11,14 @@ export interface LocalLlmModel { summary: string } -const GIB = 1024 ** 3; +const KIB = 1024; +const MIB = KIB ** 2; +const GIB = KIB ** 3; + +function formatBinaryUnit(bytes: number, unitBytes: number, suffix: string): string { + const value = bytes / unitBytes; + return `${Number(value.toFixed(value < 10 ? 1 : 0))} ${suffix}`; +} export const LOCAL_LLM_MODELS = [ { @@ -84,5 +91,11 @@ export function formatLocalLlmBytes(bytes: number): string { if (bytes >= GIB) { return `${(bytes / GIB).toFixed(1)} GiB`; } - return `${Math.round(bytes / 1024 ** 2)} MiB`; + if (bytes >= MIB) { + return formatBinaryUnit(bytes, MIB, 'MiB'); + } + if (bytes >= KIB) { + return formatBinaryUnit(bytes, KIB, 'KiB'); + } + return `${Math.round(bytes)} B`; }