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
7 changes: 4 additions & 3 deletions edge0-infer/examples/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ colors elsewhere.
always uses `127.0.0.1`, which needs no token. macOS may ask whether
`edge0-infer` may accept incoming connections.
- **Settings**: theme (System, Light, Dark); generation style, which sets only the
temperature of every request: Precise 0.2 (default), Balanced 0.7, Creative 1.0;
one system prompt for new conversations (empty uses the shared default; existing
conversations keep theirs); executable, device, prefill device and port.
temperature of every request: Precise, Balanced and Creative all send 1.0 (the
three names are kept for the picker); one system prompt for new conversations
(empty uses the shared default; existing conversations keep theirs); executable,
device, prefill device and port.

## Manual acceptance checklist

Expand Down
2 changes: 1 addition & 1 deletion edge0-infer/examples/desktop/src/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ for (const thinking of [false, true]) it(`normal HTTP request changes only tempe
const body = JSON.parse(String(init?.body));
expect(Object.keys(body).sort()).toEqual(['chat_template_kwargs', 'messages', 'model', 'stream', 'stream_options', 'temperature']);
for (const parameter of ['max_tokens', 'max_completion_tokens', 'top_p', 'top_k', 'seed', 'stop', 'presence_penalty', 'frequency_penalty', 'repetition_penalty']) expect(body).not.toHaveProperty(parameter);
expect(body.temperature).toBe(0.2);
expect(body.temperature).toBe(1.0);
expect(body.messages).toEqual([{ role: 'system', content: shared.system_prompt }, ...history]);
expect(body.chat_template_kwargs).toEqual({ enable_thinking: thinking });
});
Expand Down
2 changes: 1 addition & 1 deletion edge0-infer/examples/desktop/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import shared from '../../shared/app.json';
export const appData = shared;
export interface Message { role: 'user' | 'assistant'; content: string; reasoning_content?: string; metrics?: Metrics; stopped?: boolean; reasoningExpanded?: boolean; }
export interface Metrics { generated_count?: number; first_token_seconds?: number; input_tokens?: number; reused_tokens?: number; decode_tokens_per_second?: number; memory_peak_bytes?: number; }
export function buildRequest(history: Message[], thinking: boolean, model: string, temperature = 0.2, systemPrompt = appData.system_prompt) {
export function buildRequest(history: Message[], thinking: boolean, model: string, temperature = 1.0, systemPrompt = appData.system_prompt) {
return { model, messages: [{ role: 'system', content: systemPrompt }, ...history.map(({ role, content, reasoning_content }) => ({ role, content, ...(role === 'assistant' && reasoning_content ? { reasoning_content } : {}) }))], stream: true, stream_options: { include_usage: true }, chat_template_kwargs: { enable_thinking: thinking }, temperature };
}
const valid = (x: unknown): x is number => typeof x === 'number' && Number.isFinite(x) && x >= 0;
Expand Down
4 changes: 2 additions & 2 deletions edge0-infer/examples/desktop/src/pages/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EngineSource, Settings as Preferences } from '../state/settings';
import { temperatures, type EngineSource, type Settings as Preferences } from '../state/settings';
import { contextLabel, contextPresets, parseContext, type ContextDraft } from '../state/context';
import { appData } from '../chat';
import { validateServerPort } from '../conversation';
Expand All @@ -19,5 +19,5 @@ export function ContextField({ draft, disabled, change, running, reload }: { dra
export function Settings({ settings, port, disabled, update, setPort, browse, context }: { settings: Preferences; port: string; disabled: boolean; update: (settings: Preferences) => void; setPort: (text: string) => void; browse: () => void; context?: { draft: ContextDraft; change: (draft: ContextDraft) => void; running?: RunningContext; reload: () => void } }) {
const validPort = validateServerPort(port);
const t = (key: Parameters<typeof translate>[1]) => translate(resolveLang(settings.language), key);
return <><div className="topbar"><h1>Settings</h1></div><div className="page"><div className="page-in settings-page"><div className="page-head"><div><h2>Settings</h2></div></div><div className="section-label first">Appearance</div><div className="card"><div className="field"><label>{t('settings.language')}</label><div className="seg">{(['system', 'en', 'ru'] as const).map(value => <button key={value} className={settings.language === value ? 'on' : ''} disabled={disabled} onClick={() => update({ ...settings, language: value })}>{value === 'system' ? t('settings.languageSystem') : value === 'en' ? t('settings.languageEnglish') : t('settings.languageRussian')}</button>)}</div><div className="help">{t('settings.languageHelp')}</div></div><div className="field last"><label>Theme</label><div className="seg">{(['system', 'light', 'dark'] as const).map(theme => <button key={theme} className={settings.theme === theme ? 'on' : ''} disabled={disabled} onClick={() => update({ ...settings, theme })}>{theme[0].toUpperCase() + theme.slice(1)}</button>)}</div></div></div><div className="section-label">Conversation</div><div className="card"><div className="field"><label>Generation style</label><div className="seg">{(['precise', 'balanced', 'creative'] as const).map((style, index) => <button key={style} className={settings.generation_style === style ? 'on' : ''} disabled={disabled} onClick={() => update({ ...settings, generation_style: style })}>{style[0].toUpperCase() + style.slice(1)} · {['0.2', '0.7', '1.0'][index]}</button>)}</div><div className="help">Sets the temperature for every request. Every other sampling setting follows the model.</div></div><div className="field last"><label htmlFor="system-prompt">System prompt</label><textarea id="system-prompt" className="input" value={settings.system_prompt} placeholder={appData.system_prompt} disabled={disabled} onChange={event => update({ ...settings, system_prompt: event.target.value })}/><div className="help">Leave empty to use the default shown above. Applies to new chats.</div></div></div><div className="section-label">Engine</div><div className="card"><div className="field"><label>Executable</label><div className="seg">{sources.map(([source, label]) => <button key={source} className={settings.engine_source === source ? 'on' : ''} disabled={disabled} onClick={() => update(chooseSource(settings, source))}>{label}</button>)}</div>{settings.engine_source === 'custom' ? <><div className="inline"><input id="executable" className="input mono" aria-label="edge0-infer path" value={settings.executable} placeholder="Path to edge0-infer" disabled={disabled} onChange={event => update({ ...settings, executable: event.target.value })}/><button className="btn" disabled={disabled} onClick={browse}>Browse…</button></div><div className="help">The edge0-infer you choose. It is kept when the file is missing for now.</div></> : <div className="help">The edge0-infer that comes with this app.</div>}</div>{context && <ContextField draft={context.draft} disabled={disabled} change={context.change} running={context.running} reload={context.reload}/>}<div className="grid g2"><div className="field"><label htmlFor="device">Device</label><select id="device" className="input" disabled={disabled} value={settings.device} onChange={event => update({ ...settings, device: event.target.value })}>{['metal', 'cpu', 'vulkan'].map(device => <option key={device} value={device}>{device === 'cpu' ? 'CPU' : device[0].toUpperCase() + device.slice(1)}</option>)}</select><div className="help">A delegated model such as Edge0 145B runs on the device its engine registers - the Service page shows which one; this choice applies to the built-in engine only.</div></div><div className="field"><label htmlFor="prefill-device">Prefill device</label><select id="prefill-device" className="input" disabled={disabled} value={settings.prefill_device} onChange={event => update({ ...settings, prefill_device: event.target.value })}><option value="">Same as device</option>{['metal', 'cpu', 'vulkan'].map(device => <option key={device} value={device}>{device === 'cpu' ? 'CPU' : device[0].toUpperCase() + device.slice(1)}</option>)}</select></div></div><div className="field last"><label htmlFor="server-port">Port</label><input id="server-port" className="input port-input" placeholder="Automatic" inputMode="numeric" value={port} disabled={disabled} aria-invalid={!validPort.valid} onChange={event => setPort(event.target.value)}/><div className="help">Leave empty to pick a free port.</div>{!validPort.valid && <div role="alert">{validPort.error}</div>}</div></div></div></div></>;
return <><div className="topbar"><h1>Settings</h1></div><div className="page"><div className="page-in settings-page"><div className="page-head"><div><h2>Settings</h2></div></div><div className="section-label first">Appearance</div><div className="card"><div className="field"><label>{t('settings.language')}</label><div className="seg">{(['system', 'en', 'ru'] as const).map(value => <button key={value} className={settings.language === value ? 'on' : ''} disabled={disabled} onClick={() => update({ ...settings, language: value })}>{value === 'system' ? t('settings.languageSystem') : value === 'en' ? t('settings.languageEnglish') : t('settings.languageRussian')}</button>)}</div><div className="help">{t('settings.languageHelp')}</div></div><div className="field last"><label>Theme</label><div className="seg">{(['system', 'light', 'dark'] as const).map(theme => <button key={theme} className={settings.theme === theme ? 'on' : ''} disabled={disabled} onClick={() => update({ ...settings, theme })}>{theme[0].toUpperCase() + theme.slice(1)}</button>)}</div></div></div><div className="section-label">Conversation</div><div className="card"><div className="field"><label>Generation style</label><div className="seg">{(['precise', 'balanced', 'creative'] as const).map((style, index) => <button key={style} className={settings.generation_style === style ? 'on' : ''} disabled={disabled} onClick={() => update({ ...settings, generation_style: style })}>{style[0].toUpperCase() + style.slice(1)} · {temperatures[style].toFixed(1)}</button>)}</div><div className="help">Sets the temperature for every request. Every other sampling setting follows the model.</div></div><div className="field last"><label htmlFor="system-prompt">System prompt</label><textarea id="system-prompt" className="input" value={settings.system_prompt} placeholder={appData.system_prompt} disabled={disabled} onChange={event => update({ ...settings, system_prompt: event.target.value })}/><div className="help">Leave empty to use the default shown above. Applies to new chats.</div></div></div><div className="section-label">Engine</div><div className="card"><div className="field"><label>Executable</label><div className="seg">{sources.map(([source, label]) => <button key={source} className={settings.engine_source === source ? 'on' : ''} disabled={disabled} onClick={() => update(chooseSource(settings, source))}>{label}</button>)}</div>{settings.engine_source === 'custom' ? <><div className="inline"><input id="executable" className="input mono" aria-label="edge0-infer path" value={settings.executable} placeholder="Path to edge0-infer" disabled={disabled} onChange={event => update({ ...settings, executable: event.target.value })}/><button className="btn" disabled={disabled} onClick={browse}>Browse…</button></div><div className="help">The edge0-infer you choose. It is kept when the file is missing for now.</div></> : <div className="help">The edge0-infer that comes with this app.</div>}</div>{context && <ContextField draft={context.draft} disabled={disabled} change={context.change} running={context.running} reload={context.reload}/>}<div className="grid g2"><div className="field"><label htmlFor="device">Device</label><select id="device" className="input" disabled={disabled} value={settings.device} onChange={event => update({ ...settings, device: event.target.value })}>{['metal', 'cpu', 'vulkan'].map(device => <option key={device} value={device}>{device === 'cpu' ? 'CPU' : device[0].toUpperCase() + device.slice(1)}</option>)}</select><div className="help">A delegated model such as Edge0 145B runs on the device its engine registers - the Service page shows which one; this choice applies to the built-in engine only.</div></div><div className="field"><label htmlFor="prefill-device">Prefill device</label><select id="prefill-device" className="input" disabled={disabled} value={settings.prefill_device} onChange={event => update({ ...settings, prefill_device: event.target.value })}><option value="">Same as device</option>{['metal', 'cpu', 'vulkan'].map(device => <option key={device} value={device}>{device === 'cpu' ? 'CPU' : device[0].toUpperCase() + device.slice(1)}</option>)}</select></div></div><div className="field last"><label htmlFor="server-port">Port</label><input id="server-port" className="input port-input" placeholder="Automatic" inputMode="numeric" value={port} disabled={disabled} aria-invalid={!validPort.valid} onChange={event => setPort(event.target.value)}/><div className="help">Leave empty to pick a free port.</div>{!validPort.valid && <div role="alert">{validPort.error}</div>}</div></div></div></div></>;
}
2 changes: 1 addition & 1 deletion edge0-infer/examples/desktop/src/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface PartialDownload { id: string; directory: string; }
export type EngineSource = 'builtin' | 'custom';
export interface Settings { engine_source: EngineSource; executable: string; assets: string[]; device: string; prefill_device: string; port: number | null; context: number | null; theme: 'system' | 'light' | 'dark'; language: LanguageSetting; generation_style: 'precise' | 'balanced' | 'creative'; system_prompt: string; lan_access: boolean; download_directory: string; partial_downloads: PartialDownload[]; settings_version: number; }
export const defaultSettings: Settings = { engine_source: 'builtin', executable: '', assets: [], device: 'cpu', prefill_device: '', port: null, context: null, theme: 'system', language: 'system', generation_style: 'precise', system_prompt: '', lan_access: false, download_directory: '', partial_downloads: [], settings_version: 1 };
export const temperatures = { precise: 0.2, balanced: 0.7, creative: 1.0 } as const;
export const temperatures = { precise: 1.0, balanced: 1.0, creative: 1.0 } as const;
export function generateToken(random: Pick<Crypto, 'getRandomValues'> = crypto): string {
const bytes = random.getRandomValues(new Uint8Array(32));
return 'e0_sk_' + btoa(String.fromCharCode(...bytes)).replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
Expand Down
4 changes: 2 additions & 2 deletions edge0-infer/examples/desktop/src/status.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ it('edit truncates all subsequent turns and regenerate retains full earlier reas
expect(regenerate(messages)).toEqual(messages.slice(0, 3)); expect(buildRequest(regenerate(messages), true, 'model').messages[2]).toEqual({ role: 'assistant', content: 'reply', reasoning_content: 'thought' }); expect(messages).toHaveLength(4);
});
it('uses precise by default, each selected temperature, and fixes system prompt per conversation', () => {
expect(defaultSettings.generation_style).toBe('precise'); expect(buildRequest([], false, 'model').temperature).toBe(0.2);
expect(defaultSettings.generation_style).toBe('precise'); expect(buildRequest([], false, 'model').temperature).toBe(1.0);
const old = newConversation('old prompt'), fresh = newConversation('changed prompt');
for (const temperature of Object.values(temperatures)) expect(buildRequest([], false, 'model', temperature).temperature).toBe(temperature);
expect(buildRequest([], false, 'model', .7, old.systemPrompt).messages[0].content).toBe('old prompt'); expect(fresh.systemPrompt).toBe('changed prompt'); expect(newConversation(' ').systemPrompt).toBe(appData.system_prompt);
const html = renderToStaticMarkup(createElement(Settings, { settings: defaultSettings, port: '', disabled: false, update: noop, setPort: noop, browse: noop }));
expect(html).toContain('Precise · 0.2'); expect(html).toContain('System prompt');
expect(html).toContain('Precise · 1.0'); expect(html).toContain('System prompt');
});
it('generates exactly 32 cryptographic bytes in unpadded base64url', () => {
const random = { getRandomValues: vi.fn((array: Uint8Array) => { array.fill(255); return array; }) };
Expand Down
Loading