llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8
Redesign the library and chat pages in the cobanov.dev style
Mert Cobanov03807414b31c
diff --git a/ps5/ps5lm/library.html b/ps5/ps5lm/library.htmlindex 78a0580..7a9494b 100644--- a/ps5/ps5lm/library.html+++ b/ps5/ps5lm/library.html@@ -6,52 +6,76 @@<title>PS5LM</title><!--The model library ps5lm.elf serves on port 8082 and opens in the PS5- browser. Plain ES5 and XMLHttpRequest, no external files: the PS5 browser- renders modern bundles blank. Sized for a TV, works on a phone too.+ browser. cobanov.dev's palette; a plain list with hairline rules, the+ running model on top. Plain ES5 and XMLHttpRequest with no external files.SPDX-License-Identifier: GPL-3.0-or-later--><style>- :root { --bg: #0e0e14; --panel: #17171f; --line: rgba(235,235,245,0.12); --ink: #f2f2f7;- --soft: rgba(235,235,245,0.78); --muted: rgba(235,235,245,0.55); --accent: #8288f0; --ok: #7fd1a8; --bad: #f08a8a; }- html, body { margin: 0; background: var(--bg); color: var(--ink);- font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; }- header { display: flex; align-items: baseline; gap: 18px; padding: 20px 40px; border-bottom: 1px solid var(--line); }- header b { font-family: Menlo, Consolas, monospace; font-size: 26px; letter-spacing: -0.04em; }- header span { color: var(--muted); font-size: 18px; }- main { max-width: 1100px; margin: 0 auto; padding: 24px 40px 60px; }- h2 { font-family: Menlo, Consolas, monospace; font-size: 22px; letter-spacing: -0.03em; margin: 28px 0 14px; }- .chat { display: flex; align-items: center; gap: 18px; padding: 18px 22px; border: 1px solid var(--line);- border-left: 3px solid var(--accent); background: var(--panel); border-radius: 6px; font-size: 22px; }- .chat .what { flex: 1; color: var(--soft); }- .row { display: flex; align-items: center; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); }- .row .info { flex: 1; }- .row .name { font-size: 24px; font-weight: 600; }- .row .note { color: var(--muted); font-size: 18px; margin-top: 4px; }- .row .size { color: var(--muted); font-size: 18px; width: 110px; text-align: right; }- .bar { height: 8px; background: var(--line); border-radius: 4px; margin-top: 10px; overflow: hidden; }- .bar i { display: block; height: 100%; background: var(--accent); width: 0; }- .status { color: var(--muted); font-size: 17px; margin-top: 6px; }- .status.bad { color: var(--bad); }- button, a.btn { font-size: 20px; padding: 12px 22px; border-radius: 6px; border: 1px solid rgba(235,235,245,0.22);- background: #16161d; color: var(--ink); text-decoration: none; cursor: pointer; font-family: inherit; }- button.primary, a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }- button:focus, a.btn:focus { outline: 3px solid var(--accent); outline-offset: 2px; }- .ok { color: var(--ok); }- p.foot { color: var(--muted); font-size: 16px; margin-top: 28px; }+ :root {+ --bg: #000000; --surface: #0b0b0b; --raised: #0f0f0f; --field: #0d0b0b;+ --border: #2b2523; --text: #fafafa; --body: #ebebeb; --muted: #aaa39f; --faint: #8f8f8f;+ --accent: #6e81e4; --fill: #0e1e6a; --fill-hover: #152886; --warn: #e5a29a;+ }+ html { font-size: clamp(16px, 1.15vw, 23px); -webkit-text-size-adjust: 100%; }+ html, body { margin: 0; background: var(--bg); color: var(--body);+ font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; line-height: 1.6; }+ a { color: var(--accent); text-decoration: none; }+ :focus-visible, button:focus, a:focus { outline: 2px solid var(--accent); outline-offset: 3px; }++ .top { display: flex; align-items: center; gap: 1rem; height: 3.5rem; padding: 0 1.5rem;+ border-bottom: 1px solid var(--border); }+ .brand { color: var(--text); font-weight: 600; letter-spacing: -0.02em; flex: 1; }+ .top a { font-size: 0.875rem; padding: 0.5rem 0; }++ main { max-width: 46rem; margin: 0 auto; padding: 2.5rem 1.5rem 3rem; }+ h1 { color: var(--text); font-size: 1.875rem; font-weight: 400; letter-spacing: -0.02em; margin: 0 0 1.5rem; }+ h2 { color: var(--muted); font-size: 0.875rem; font-weight: 500; margin: 2.5rem 0 0.25rem; }++ .now { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.1rem; margin-bottom: 1.5rem;+ background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }+ .now .what { flex: 1; color: var(--muted); }+ .now .what b { color: var(--text); font-weight: 500; }+ .now .what.problem { color: var(--warn); }++ .list { border-top: 1px solid var(--border); }+ .row { display: flex; align-items: center; gap: 1rem; padding: 1.1rem 0; border-bottom: 1px solid var(--border); }+ .info { flex: 1; min-width: 0; }+ .name { color: var(--text); font-weight: 500; }+ .note { color: var(--muted); font-size: 0.875rem; }+ .size { color: var(--faint); font-size: 0.875rem; white-space: nowrap; }+ .progress { height: 3px; background: var(--border); border-radius: 2px; margin: 0.6rem 0 0.35rem; overflow: hidden; }+ .progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.6s linear; }+ .status { color: var(--faint); font-size: 0.8125rem; }+ .status.problem { color: var(--warn); }+ .tag { color: var(--accent); font-size: 0.875rem; white-space: nowrap; }++ .actions { display: flex; align-items: center; gap: 0.5rem; }+ button, a.button { font: inherit; font-size: 0.875rem; font-weight: 500; line-height: 1; white-space: nowrap;+ border-radius: 8px; padding: 0.7rem 1.1rem; cursor: pointer; display: inline-block; }+ .primary { color: #fff; background: var(--fill); border: 1px solid var(--fill); }+ .primary:hover { background: var(--fill-hover); border-color: var(--fill-hover); }+ .ghost { color: var(--muted); background: var(--field); border: 1px solid var(--border); }+ .ghost:hover { color: var(--text); background: #171514; }++ footer { color: var(--faint); font-size: 0.8125rem; margin-top: 2.5rem; }+ @media (max-width: 560px) {+ .row { flex-wrap: wrap; }+ .info { flex-basis: 100%; }+ }</style></head><body>-<header><b>ps5lm</b><span>models on your PlayStation 5</span></header>+<header class="top">+ <span class="brand">ps5lm</span>+ <a id="chat-link" href="#" style="display:none">Chat</a>+</header><main>- <div class="chat" id="chat"><span class="what">Starting...</span></div>-- <h2>Models</h2>- <div id="catalog"></div>-- <h2 id="other-title" style="display:none">Other models on the console</h2>- <div id="other"></div>-- <p class="foot" id="foot"></p>+ <h1>Models</h1>+ <div class="now" id="now"><span class="what">Loading</span></div>+ <div class="list" id="catalog"></div>+ <h2 id="other-title" style="display:none">Copied to the console</h2>+ <div class="list" id="other"></div>+ <footer id="foot"></footer></main><script>(function () {@@ -64,8 +88,14 @@if (text !== undefined) e.textContent = text;return e;}- function gb(bytes) { return (bytes / 1073741824).toFixed(bytes < 1073741824 ? 2 : 1) + ' GB'; }- function mb(bytes) { return (bytes / 1048576).toFixed(1) + ' MB/s'; }+ function size(bytes) {+ var gb = bytes / 1073741824;+ return gb >= 1 ? gb.toFixed(1) + ' GB' : Math.round(bytes / 1048576) + ' MB';+ }+ // Qwen3.5-2B-Q4_K_M.gguf reads as Qwen3.5 2B.+ function short(file) {+ return file.replace(/\.gguf$/, '').replace(/-(UD-)?(I?Q[0-9].*|BF16|F16|F32)$/i, '').replace(/-/g, ' ');+ }function post(path) {var x = new XMLHttpRequest();@@ -73,80 +103,100 @@x.onloadend = refresh;x.send();}- function button(label, cls, path) {- var b = el('button', cls, label);+ function button(label, kind, path) {+ var b = el('button', kind, label);+ b.type = 'button';b.onclick = function () { post(path); };return b;}- function renderChat(chat) {- var box = document.getElementById('chat');+ function chatUrl() { return 'http://' + host + ':' + state.chat.port + '/'; }++ function renderNow() {+ var box = document.getElementById('now');+ var chat = state.chat;+ var link = document.getElementById('chat-link');box.innerHTML = '';- var url = 'http://' + host + ':' + chat.port + '/';+ var what = el('span', 'what');if (chat.model && chat.ready) {- box.appendChild(el('span', 'what', 'Running ' + chat.model));- var a = el('a', 'btn primary', 'Open chat');- a.href = url;- box.appendChild(a);- box.appendChild(button('Stop', '', '/api/stop'));+ what.appendChild(document.createTextNode('Running '));+ what.appendChild(el('b', '', short(chat.model)));+ box.appendChild(what);+ var open = el('a', 'button primary', 'Open chat');+ open.href = chatUrl();+ box.appendChild(open);+ box.appendChild(button('Stop', 'ghost', '/api/stop'));+ link.href = chatUrl();+ link.style.display = '';} else if (chat.model) {- box.appendChild(el('span', 'what', 'Loading ' + chat.model + '...'));- } else if (chat.error) {- box.appendChild(el('span', 'what', chat.error));+ what.appendChild(document.createTextNode('Starting '));+ what.appendChild(el('b', '', short(chat.model)));+ box.appendChild(what);+ link.style.display = 'none';} else {- box.appendChild(el('span', 'what', 'Download a model below, then run it.'));+ if (chat.error) {+ what.className = 'what problem';+ what.textContent = chat.error;+ } else {+ what.textContent = 'Nothing running. Download a model, then run it.';+ }+ box.appendChild(what);+ link.style.display = 'none';}}- function renderModel(m, chat) {- var row = el('div', 'row');+ function row(m) {+ var r = el('div', 'row');var info = el('div', 'info');info.appendChild(el('div', 'name', m.name));- info.appendChild(el('div', 'note', m.note));+ if (m.note) info.appendChild(el('div', 'note', m.note));var d = m.download;- if (d && d.active) {- var bar = el('div', 'bar');+ var downloading = d && d.active;+ if (downloading) {+ var bar = el('div', 'progress');var fill = el('i');fill.style.width = (d.total ? Math.floor(100 * d.done / d.total) : 0) + '%';bar.appendChild(fill);info.appendChild(bar);- info.appendChild(el('div', 'status', gb(d.done) + ' of ' + gb(d.total) + (d.speed ? ', ' + mb(d.speed) : '')));+ info.appendChild(el('div', 'status', size(d.done) + ' of ' + size(d.total) ++ (d.speed ? ', ' + (d.speed / 1048576).toFixed(1) + ' MB/s' : '')));} else if (d && d.error && !m.installed) {- info.appendChild(el('div', 'status' + (d.error === 'paused' ? '' : ' bad'),- d.error === 'paused' ? 'Paused at ' + gb(d.done) : d.error));+ var paused = d.error === 'paused' || d.error === 'cancelled';+ info.appendChild(el('div', paused ? 'status' : 'status problem',+ paused ? 'Paused at ' + size(d.done) : d.error));}- row.appendChild(info);- row.appendChild(el('div', 'size', gb(m.size)));+ r.appendChild(info);+ r.appendChild(el('span', 'size', size(m.size)));- if (d && d.active) {- row.appendChild(button('Cancel', '', '/api/cancel?id=' + encodeURIComponent(m.id)));- } else if (m.installed && state.max_model && m.size > state.max_model) {- row.appendChild(el('span', 'status bad', 'Too big for a payload'));- row.appendChild(button('Delete', '', '/api/delete?file=' + encodeURIComponent(m.file)));+ var actions = el('div', 'actions');+ var tooBig = state.max_model && m.size > state.max_model;+ if (downloading) {+ actions.appendChild(button('Cancel', 'ghost', '/api/cancel?id=' + encodeURIComponent(m.id)));+ } else if (m.installed && state.chat.model === m.file) {+ actions.appendChild(el('span', 'tag', state.chat.ready ? 'Running' : 'Starting'));+ } else if (m.installed && tooBig) {+ actions.appendChild(el('span', 'status problem', 'Too big to run'));+ actions.appendChild(button('Delete', 'ghost', '/api/delete?file=' + encodeURIComponent(m.file)));} else if (m.installed) {- if (chat.model === m.file) {- row.appendChild(el('span', 'ok', chat.ready ? 'Running' : 'Loading'));- } else {- row.appendChild(button('Run', 'primary', '/api/run?file=' + encodeURIComponent(m.file)));- row.appendChild(button('Delete', '', '/api/delete?file=' + encodeURIComponent(m.file)));- }+ actions.appendChild(button('Run', 'primary', '/api/run?file=' + encodeURIComponent(m.file)));+ actions.appendChild(button('Delete', 'ghost', '/api/delete?file=' + encodeURIComponent(m.file)));} else {- row.appendChild(button(d && d.done ? 'Resume' : 'Download', 'primary',+ actions.appendChild(button(d && d.done ? 'Resume' : 'Download', 'primary','/api/download?id=' + encodeURIComponent(m.id)));}- return row;+ r.appendChild(actions);+ return r;}function render() {- renderChat(state.chat);+ renderNow();var list = document.getElementById('catalog');list.innerHTML = '';var known = {};for (var i = 0; i < state.catalog.length; i++) {known[state.catalog[i].file] = true;- list.appendChild(renderModel(state.catalog[i], state.chat));+ list.appendChild(row(state.catalog[i]));}- // Models copied over FTP or USB that are not in the catalog.var other = document.getElementById('other');other.innerHTML = '';var count = 0;@@ -154,13 +204,13 @@var f = state.installed[j];if (known[f.file]) continue;count++;- other.appendChild(renderModel({ id: '', name: f.file, note: 'Copied to /data/PS5LM/models',- file: f.file, size: f.size, installed: true }, state.chat));+ other.appendChild(row({ id: '', name: short(f.file), note: '', file: f.file, size: f.size, installed: true }));}document.getElementById('other-title').style.display = count ? '' : 'none';- document.getElementById('foot').textContent = 'PS5LM ' + state.version + '. ' +- (state.free >= 0 ? gb(state.free) + ' free on the console. ' : '') +- (state.ip ? 'From a phone or computer on the same network: http://' + state.ip + ':' + state.port + '/' : '');+ var foot = 'PS5LM ' + state.version + '.';+ if (state.free >= 0) foot += ' ' + size(state.free) + ' free.';+ if (state.ip) foot += ' On a phone or computer: http://' + state.ip + ':' + state.port;+ document.getElementById('foot').textContent = foot;}function refresh() {diff --git a/ps5/webui/index.html b/ps5/webui/index.htmlindex 3cf07c5..482885d 100644--- a/ps5/webui/index.html+++ b/ps5/webui/index.html@@ -5,108 +5,156 @@<meta name="viewport" content="width=device-width, initial-scale=1"><title>PS5LM</title><!--- The chat page llama-server serves on the PS5 (llama-server --path www).- llama.cpp's own web UI renders blank in the PS5 browser, so this page sticks- to plain ES5 and XMLHttpRequest, with no external files. Sized for a TV.+ The chat page llama-server serves on the PS5 (ps5lm.elf, port 8081).+ cobanov.dev's palette, laid out like a plain chat client: one reading+ column, your messages in a quiet box, answers as text. Plain ES5 and+ XMLHttpRequest with no external files, because the PS5 browser renders+ modern bundles blank. Sized from the viewport, so it reads on a TV and on+ a phone.SPDX-License-Identifier: GPL-3.0-or-later--><style>:root {- --bg: #0b0d12;- --panel: #151923;- --text: #e8ebf2;- --muted: #8a93a6;- --accent: #3d7bfd;- --user: #1f2a44;- --border: #262c3a;+ --bg: #000000; --surface: #0b0b0b; --raised: #0f0f0f; --field: #0d0b0b;+ --border: #2b2523; --text: #fafafa; --body: #ebebeb; --muted: #aaa39f; --faint: #8f8f8f;+ --accent: #6e81e4; --fill: #0e1e6a; --fill-hover: #152886;}- html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);- font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; }+ html { font-size: clamp(16px, 1.15vw, 23px); -webkit-text-size-adjust: 100%; }+ html, body { margin: 0; height: 100%; background: var(--bg); color: var(--body);+ font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; line-height: 1.6; }body { display: flex; flex-direction: column; }- header { display: flex; align-items: baseline; gap: 16px; padding: 18px 32px;+ a { color: var(--accent); text-decoration: none; }+ :focus-visible, button:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 3px; }++ .top { display: flex; align-items: center; gap: 1rem; height: 3.5rem; padding: 0 1.5rem;border-bottom: 1px solid var(--border); }- header h1 { margin: 0; font-size: 30px; letter-spacing: 0.5px; }- header span { color: var(--muted); font-size: 20px; flex: 1; }- header a { color: var(--accent); font-size: 20px; text-decoration: none; }- #log { flex: 1; overflow-y: auto; padding: 24px 32px; }- .msg { max-width: 1100px; margin: 0 0 18px; padding: 16px 22px; border-radius: 14px;- font-size: 26px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }- .user { background: var(--user); margin-left: auto; }- .bot { background: var(--panel); border: 1px solid var(--border); }- .think { color: var(--muted); font-style: italic; font-size: 22px; }- .meta { color: var(--muted); font-size: 18px; margin-top: 8px; }- form { display: flex; gap: 14px; padding: 18px 32px 26px; border-top: 1px solid var(--border); }- #input { flex: 1; font-size: 26px; padding: 16px 18px; border-radius: 12px;- border: 1px solid var(--border); background: var(--panel); color: var(--text); }- button { font-size: 24px; padding: 0 30px; border-radius: 12px; border: 0;- background: var(--accent); color: #fff; }- button.stop { background: #a83a3a; }+ .brand { color: var(--text); font-weight: 600; letter-spacing: -0.02em; }+ .model { color: var(--muted); font-size: 0.875rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }+ .top a { font-size: 0.875rem; padding: 0.5rem 0; }++ .scroll { flex: 1; overflow-y: auto; }+ .column { max-width: 46rem; margin: 0 auto; padding: 2rem 1.5rem; }++ .empty { padding-top: 12vh; }+ .empty h1 { color: var(--text); font-size: 1.875rem; font-weight: 400; letter-spacing: -0.02em; margin: 0 0 0.5rem; }+ .empty p { color: var(--muted); margin: 0 0 2rem; }+ .ideas { display: flex; flex-direction: column; gap: 0.6rem; }+ .idea { text-align: left; font: inherit; font-size: 1rem; color: var(--body); background: var(--surface);+ border: 1px solid var(--border); border-radius: 10px; padding: 0.85rem 1.1rem; cursor: pointer; }+ .idea:hover { background: var(--raised); color: var(--text); }++ .msg { margin: 0 0 1.75rem; white-space: pre-wrap; word-wrap: break-word; }+ .me { display: flex; justify-content: flex-end; }+ .me div { background: var(--raised); border: 1px solid var(--border); color: var(--text);+ border-radius: 14px; padding: 0.6rem 1rem; max-width: 80%; }+ .bot { color: var(--body); }+ .bot .meta { display: block; color: var(--faint); font-size: 0.8125rem; margin-top: 0.4rem; }+ .bot .error { color: #e5a29a; }+ .caret { display: inline-block; width: 0.5em; height: 1.1em; vertical-align: text-bottom; background: var(--muted); }++ .composer { border-top: 1px solid var(--border); background: var(--bg); }+ .composer form { max-width: 46rem; margin: 0 auto; padding: 1rem 1.5rem 1.25rem; display: flex; gap: 0.6rem; }+ .composer input { flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--surface);+ border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem 1rem; }+ .composer input::placeholder { color: var(--faint); }+ .composer button { font: inherit; font-size: 0.9375rem; font-weight: 500; color: #fff; background: var(--fill);+ border: 0; border-radius: 12px; padding: 0 1.4rem; cursor: pointer; }+ .composer button:hover { background: var(--fill-hover); }+ .composer button.stop { background: var(--surface); color: var(--text); border: 1px solid var(--border); }</style></head><body>-<header><h1>PS5LM</h1><span id="model">llama.cpp on PlayStation 5</span><a id="models" href="#">Models</a></header>-<div id="log"></div>-<form id="form">- <input id="input" type="text" autocomplete="off" placeholder="Type a message">- <button id="send" type="submit">Send</button>-</form>+<header class="top">+ <span class="brand">ps5lm</span>+ <span class="model" id="model"></span>+ <a id="models" href="#">Models</a>+</header>++<div class="scroll" id="scroll">+ <div class="column" id="log">+ <div class="empty" id="empty">+ <h1>Ask something</h1>+ <p>A language model running on this PS5's own processor.</p>+ <div class="ideas">+ <button class="idea" type="button">Who are you?</button>+ <button class="idea" type="button">Write a haiku about the PS5</button>+ <button class="idea" type="button">Explain how a CPU works in two sentences</button>+ </div>+ </div>+ </div>+</div>++<div class="composer">+ <form id="form">+ <input id="input" type="text" autocomplete="off" placeholder="Message">+ <button id="send" type="submit">Send</button>+ </form>+</div>+<script>(function () {+ var SYSTEM = 'You are a helpful assistant running on a PlayStation 5. ' ++ 'Answer in one to three short sentences, in the language the user writes in.';var log = document.getElementById('log');+ var scroller = document.getElementById('scroll');var form = document.getElementById('form');var input = document.getElementById('input');var send = document.getElementById('send');- var SYSTEM = 'You are a helpful assistant running on a PlayStation 5. ' +- 'Answer in one to three short sentences, in the language the user writes in.';var messages = [];var xhr = null;// ps5lm.elf serves its model library on port 8082.document.getElementById('models').href = 'http://' + location.hostname + ':8082/';- function bubble(cls, text) {+ var info = new XMLHttpRequest();+ info.open('GET', '/v1/models');+ info.onload = function () {+ try {+ var id = JSON.parse(info.responseText).data[0].id;+ // Qwen3.5-2B-Q4_K_M.gguf reads as Qwen3.5 2B.+ document.getElementById('model').textContent = id.split('/').pop().replace(/\.gguf$/, '')+ .replace(/-(UD-)?(I?Q[0-9].*|BF16|F16|F32)$/i, '').replace(/-/g, ' ');+ } catch (e) {}+ };+ info.send();++ function add(cls) {+ var empty = document.getElementById('empty');+ if (empty) empty.parentNode.removeChild(empty);var div = document.createElement('div');div.className = 'msg ' + cls;- div.textContent = text || '';log.appendChild(div);- log.scrollTop = log.scrollHeight;return div;}-+ function bottom() { scroller.scrollTop = scroller.scrollHeight; }function busy(on) {send.textContent = on ? 'Stop' : 'Send';send.className = on ? 'stop' : '';}- // The model name, for the header.- var info = new XMLHttpRequest();- info.open('GET', '/v1/models');- info.onload = function () {- try {- var id = JSON.parse(info.responseText).data[0].id;- document.getElementById('model').textContent = id.split('/').pop() + ' on PlayStation 5';- } catch (e) {}- };- info.send();-function ask(text) {messages.push({ role: 'user', content: text });- // Keep the request small: the console's context is 4096 tokens.if (messages.length > 12) messages = messages.slice(messages.length - 12);- bubble('user', text);- var out = bubble('bot', '');- var think = null;- var answer = '';- var reasoning = '';- var seen = 0;- var pending = '';- var started = Date.now();+ var mine = add('me');+ var box = document.createElement('div');+ box.textContent = text;+ mine.appendChild(box);++ var out = add('bot');+ var body = document.createTextNode('');+ var caret = document.createElement('span');+ caret.className = 'caret';+ out.appendChild(body);+ out.appendChild(caret);+ bottom();++ var answer = '', seen = 0, pending = '';xhr = new XMLHttpRequest();xhr.open('POST', '/v1/chat/completions');xhr.setRequestHeader('Content-Type', 'application/json');- // Server-sent events arrive in pieces; parse whole "data:" lines as they come.+ // Server-sent events arrive in pieces: handle whole "data:" lines.xhr.onprogress = function () {pending += xhr.responseText.substring(seen);seen = xhr.responseText.length;@@ -120,38 +168,40 @@var chunk;try { chunk = JSON.parse(data); } catch (e) { continue; }var delta = chunk.choices && chunk.choices[0] && chunk.choices[0].delta;- if (delta && delta.reasoning_content) {- if (!think) { think = document.createElement('div'); think.className = 'think'; out.appendChild(think); }- reasoning += delta.reasoning_content;- think.textContent = reasoning;- }if (delta && delta.content) {answer += delta.content;- if (!out.lastChild || out.lastChild.nodeType !== 3) out.appendChild(document.createTextNode(''));- out.lastChild.nodeValue = answer;+ body.nodeValue = answer;}if (chunk.timings) {- var meta = document.createElement('div');+ var meta = document.createElement('span');meta.className = 'meta';meta.textContent = chunk.timings.predicted_n + ' tokens, ' +- chunk.timings.predicted_per_second.toFixed(1) + ' tok/s, ' +- ((Date.now() - started) / 1000).toFixed(1) + ' s';+ chunk.timings.predicted_per_second.toFixed(1) + ' tokens a second';out.appendChild(meta);}- log.scrollTop = log.scrollHeight;+ bottom();}};xhr.onloadend = function () {xhr.onprogress();- if (xhr.status && xhr.status !== 200 && !answer) out.textContent = 'Error ' + xhr.status + ': ' + xhr.responseText;- if (answer) messages.push({ role: 'assistant', content: answer });+ if (caret.parentNode) caret.parentNode.removeChild(caret);+ if (!answer) {+ var err = document.createElement('span');+ err.className = 'error';+ err.textContent = xhr.status === 0 ? 'Stopped.' :+ 'No answer (' + xhr.status + '). Check that a model is running in the library.';+ out.appendChild(err);+ } else {+ messages.push({ role: 'assistant', content: answer });+ }xhr = null;busy(false);+ bottom();input.focus();};- // Small models on four CPU cores: short answers, no thinking phase.+ // Small models on a few CPU cores: short answers, no thinking phase.xhr.send(JSON.stringify({messages: [{ role: 'system', content: SYSTEM }].concat(messages),stream: true,@@ -170,8 +220,10 @@ask(text);};- bubble('bot', 'Hi! I am a language model running on this PlayStation 5, on its own CPU. Ask me anything.');- input.focus();+ var ideas = document.querySelectorAll('.idea');+ for (var k = 0; k < ideas.length; k++) {+ ideas[k].onclick = function () { if (!xhr) ask(this.textContent); };+ }})();</script></body>