Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/tools/local-llm-playground/local-llm.models.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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');
});
});
17 changes: 15 additions & 2 deletions src/tools/local-llm-playground/local-llm.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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`;
}
Loading