okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Trial2 merge f-0291-pr-nv (97b3d614f)1306424be

main
6.0 KiB102 linesraw
1import { api } from './client';
2
3/** A saved tuning, as Strata Control reports it (the same store the Terminal uses). */
4export interface TunePreset {
5  id: string;
6  name: string;
7  active: boolean;
8  created?: string;
9  answers?: { class: 'exact' | 'placement' | 'nonrepeatable' | 'quality'; fields: string[]; default_repeatable?: boolean };
10  settings?: { args: Record<string, unknown>; env: Record<string, unknown>; per_request: Record<string, unknown> };
11  gain_pct?: number | null;
12  decode_tok_s?: number | null;
13  baseline_decode_tok_s?: number | null;
14  recheck?: { last_ok?: string | null; last_result?: { verdict?: string; reason?: string } | null } | null;
15  slot?: string;
16}
17
18export interface TuneStatus {
19  ok: boolean;
20  slot: string;
21  suggested_name: string;
22  active: TunePreset | null;
23  /** fresh, soft (a short check is offered) or hard (the settings are not applied; tune again). */
24  state: 'fresh' | 'soft' | 'hard' | null;
25  reasons: string[];
26  presets: TunePreset[];
27  can_undo: boolean;
28  /** the tuning was switched off for these choices (it is kept: last_active can be switched on again) */
29  switched_off?: boolean;
30  last_active?: TunePreset | null;
31}
32
33export interface TuneProgress { stage: string; text: string | null; minutesLeft: number | null; runsDone: number; runsPlanned: number; elapsedS: number; step: string; /** each measurement so far, as decode tokens per second */ speeds?: { label: string; tok_s: number }[] }
34
35export interface TuneResult {
36  summary: string;
37  outcome?: 'improved' | 'default_confirmed' | 'inconclusive' | 'base_failed' | 'cancelled';
38  message?: string;
39  gain_pct?: number;
40  seconds?: number;
41  pairs?: number;
42  faster_pairs?: number;
43  base?: { decode_tok_s?: number | null };
44  chosen?: { decode_tok_s?: number | null };
45  answers?: { class: 'exact' | 'placement' | 'nonrepeatable' | 'quality'; fields: string[]; default_repeatable?: boolean };
46  preset?: { id: string; name: string } | null;
47  notes?: string[];
48  /** what the screen shows: faster | already_fastest | busy_pc | failed | stopped */
49  code?: 'faster' | 'already_fastest' | 'busy_pc' | 'failed' | 'stopped';
50  /** busy_pc: noisy | drift | not_tried; failed: start_failed | no_memory */
51  reason_code?: string;
52  values?: { gain_pct?: number; gain_decode_pct?: number; base_tok_s?: number | null; tuned_tok_s?: number | null; noise_pct?: number | null; drift_pct?: number | null; minutes?: number; pairs?: number; faster_pairs?: number; preset_name?: string | null };
53  verdict?: 'keep' | 'retune' | 'inconclusive';
54  reason?: string;
55}
56
57const q = (o: Record<string, string | undefined>) => Object.entries(o).filter(([, v]) => v).map(([k, v]) => `${k}=${encodeURIComponent(v as string)}`).join('&');
58
59export const tuneStatus = (model: string, resourceProfile: string, vision: string) =>
60  api.get<TuneStatus>(`/api/native/tune/status?${q({ model, resourceProfile, vision })}`);
61export const tunePresetAction = (id: string, action: 'apply' | 'rename' | 'delete' | 'undo', body: Record<string, unknown> = {}) =>
62  api.post(`/api/native/tune/presets/${id}/${action}`, body);
63export const tuneOff = (model: string, resourceProfile: string, vision: string) =>
64  api.post('/api/native/tune/off', { model, resourceProfile, vision });
65/** What a start will really run: the saved tuning's values on top of the configuration (Expert mode shows these). */
66export const tuneEffective = (model: string, resourceProfile: string, vision: string) =>
67  api.get<{ applied: boolean; preset: { id: string; name: string } | null; args: string[]; env: Record<string, string>; changed: { flag: string; was: string | null; now: string | null }[]; why_not?: string | null }>(`/api/native/tune/effective?${q({ model, resourceProfile, vision })}`);
68export const tuneUndo = (model: string, resourceProfile: string, vision: string) =>
69  api.post('/api/native/tune/undo', { model, resourceProfile, vision });
70
71/** The four answer classes, in the words the app uses (the Terminal prints the same sentences). */
72export const ANSWER_NOTICE: Record<string, string> = {
73  exact: 'Answers are identical to the standard setup.',
74  placement: 'Answers may differ slightly from the standard setup.',
75  nonrepeatable: 'Answers are not repeatable run to run.',
76  quality: 'Includes a quality setting that changes the numbers.',
77};
78
79/** Where the standard setup is itself not repeatable (RTX 3060 in low-RAM mode, Arc A750), an exact setting cannot promise identical answers. */
80export const answerNotice = (cls?: string, defaultRepeatable?: boolean) =>
81  cls === 'exact' && defaultRepeatable === false ? 'Answers can differ from run to run on this PC even with the standard setup; this setting does not add to that.' : ANSWER_NOTICE[cls ?? ''] ?? '';
82
83/**
84 * Why Start tuning is greyed out (#4804). Every condition that disables it, in the order they are checked:
85 *  - 'other'      another operation (a download, a load, a first-run step) is running: tuning unloads the model, so it waits;
86 *  - 'loading'    the saved tunings of this model have not been read yet (the first read after a download can take a few seconds);
87 *  - 'unreadable' reading them failed, so there is nothing to tune from until the window is opened again;
88 *  - 'busy'       the last click is still being carried out: a moment, so it gets no sentence;
89 * and null when the button works. Only the first three are long enough for a person to wonder, so only they have words.
90 */
91export type TuneBlock = 'other' | 'loading' | 'unreadable' | 'busy' | null;
92export function tuneStartBlock(input: { busy: boolean; otherRunning: boolean; status: unknown; error: string }): TuneBlock {
93  if (input.otherRunning) return 'other';
94  if (!input.status) return input.error ? 'unreadable' : 'loading';
95  if (input.busy) return 'busy';
96  return null;
97}
98export const TUNE_BLOCK_TEXT: Record<'other' | 'loading' | 'unreadable', string> = {
99  other: 'Finish the current operation first.',
100  loading: 'Strata is still checking this model for saved tunings. Start tuning works as soon as that is done.',
101  unreadable: 'Strata could not read the tuning details for this model, so tuning cannot start. Close this window and open it again.',
102};