okami.mom/strata

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

Niko1221Merge f-split-fb4 (201d674e9) into f-split-int: cloudflared discovery, settings file, Gyro minimum engine, two models on two GPUs261145baa

main
2.6 KiB43 linesraw
1import { tr } from '../lib/i18n';
2import { useCallback, useEffect, useState } from 'react';
3import { api } from '../lib/client';
4import { Btn, ErrorNotice } from './ui';
5import { issueText, type SettingsFileInfo } from '../lib/run-config-issues';
6
7/**
8 * Expert settings: the model's settings live in one text file (its run configuration). A power user opens it in the system
9 * text editor and changes any engine option; the change applies the next time the model starts. The file is checked here and
10 * again before the model starts, and a mistake is shown in plain words with its line.
11 */
12export function NativeSettingsFile({ model }: { model: string }) {
13    const [info, setInfo] = useState<SettingsFileInfo | null>(null), [pending, setPending] = useState(false), [error, setError] = useState('');
14    const check = useCallback(() => api.get<SettingsFileInfo>(`/api/native/models/${model}/settings-file`).then(value => { setInfo(value); setError(''); }).catch(() => setInfo(null)), [model]);
15    useEffect(() => {
16        void check();
17        // Back from the editor: look at the file again.
18        const again = () => void check();
19        window.addEventListener('focus', again);
20        return () => window.removeEventListener('focus', again);
21    }, [check]);
22    async function open() {
23        setPending(true);
24        setError('');
25        try {
26            setInfo(await api.post<SettingsFileInfo>(`/api/native/models/${model}/settings-file`, {}));
27        }
28        catch (e) {
29            setError((e as Error).message);
30        }
31        finally {
32            setPending(false);
33        }
34    }
35    const errors = info?.issues.filter(i => i.level === 'error') ?? [], warnings = info?.issues.filter(i => i.level === 'warning') ?? [];
36    return <div className="native-settings-file">
37    <h3 className="small strong">{tr("Settings file")}</h3>
38    <div className="row"><Btn size="sm" disabled={pending || !info} onClick={() => void open()}>{tr("Open settings file")}</Btn><span className="small muted">{tr("Changes you make in the file apply the next time the model starts.")}</span></div>
39    {tr(error ? <ErrorNotice message={error} next={tr("Open the file from its folder instead, or try again.")}/> : null)}
40    {tr(errors.length ? <><ErrorNotice message={tr("Your settings file has a mistake, so the model will not start until it is fixed.")} next={tr("Open the settings file, fix the lines below, and load the model again.")}/>{tr(errors.map((issue, i) => <p className="small" key={`e${i}`}>{tr(issueText(issue))}</p>))}</> : null)}
41    {tr(warnings.map((issue, i) => <p className="small muted" key={`w${i}`}>{tr(issueText(issue))}</p>))}
42  </div>;
43}