char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
1.5 KiB48 linesraw
1/**
2 * Model load progress helpers for the /models/sse surfaces
3 * (selector row and chat message).
4 */
5
6import { MODEL_LOAD_STAGE_LABELS, MODEL_LOAD_TAIL_SHARE } from '$lib/constants';
7
8/**
9 * Human label for a model load stage.
10 */
11export function modelLoadStageLabel(stage: ApiModelLoadStage): string {
12	return MODEL_LOAD_STAGE_LABELS[stage];
13}
14
15/**
16 * Overall load fraction (0.0 -> 1.0) across the declared stage plan.
17 * text_model fills [0, 1 - tail], each later phase owns one tail slice.
18 */
19export function modelLoadFraction(progress: ModelLoadProgress | null): number {
20	if (!progress) return 0;
21
22	// The server may emit a progress event before the stage plan is known, so
23	// `stages` can be absent. Fall back to the raw value in that case.
24	const { current, stages = [], value } = progress;
25	const tailCount = Math.max(stages.length - 1, 0);
26	const textCeiling = 1 - tailCount * MODEL_LOAD_TAIL_SHARE;
27	const idx = stages.indexOf(current);
28
29	if (idx <= 0) {
30		return value * textCeiling;
31	}
32
33	return textCeiling + (idx - 1 + value) * MODEL_LOAD_TAIL_SHARE;
34}
35
36/**
37 * Single line describing load progress: active stage label and overall percent.
38 * Returns null when there is no progress to show.
39 */
40export function modelLoadProgressText(progress: ModelLoadProgress | null): string | null {
41	if (!progress) return null;
42
43	const label = modelLoadStageLabel(progress.current);
44
45	if (!label) return null;
46
47	return `${label} ${Math.round(modelLoadFraction(progress) * 100)}%`;
48}