aleada commited on
Commit
9384fec
·
verified ·
1 Parent(s): 48879bc

reasoning-parser advisor

Browse files
Files changed (2) hide show
  1. app.js +113 -107
  2. progress.js +123 -0
app.js CHANGED
@@ -1,107 +1,113 @@
1
- /**
2
- * The page: one repo id in, one serving decision out.
3
- *
4
- * All rules live in parser_advice.js, which the parity gate holds to the
5
- * Python implementation. Nothing here decides anything — it fetches,
6
- * calls, and renders, so a rule can never be quietly different in the UI
7
- * from the one that was tested.
8
- */
9
- import { ALL_MARKERS, advise, fetchTemplate } from './parser_advice.js';
10
-
11
- const $ = (id) => document.getElementById(id);
12
- const out = $('out');
13
- const esc = (s) => String(s).replace(/[&<>"]/g, (c) =>
14
- ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
15
-
16
- function renderRules() {
17
- const seen = new Map();
18
- for (const [parser, marks] of Object.entries(ALL_MARKERS)) {
19
- const key = marks.join(' ');
20
- if (!seen.has(key)) seen.set(key, []);
21
- seen.get(key).push(parser);
22
- }
23
- $('rules').innerHTML = [...seen.entries()].map(([marks, parsers]) =>
24
- `<tr><td><code>${parsers.map(esc).join('</code>, <code>')}</code></td>` +
25
- `<td><code>${marks.split(' ').map(esc).join('</code> <code>')}</code></td></tr>`
26
- ).join('');
27
- }
28
-
29
- function card(cls, title, body) {
30
- return `<div class="card ${cls}"><h3>${title}</h3>${body}</div>`;
31
- }
32
-
33
- function render(repo, source, result) {
34
- const meta = `<div class="meta">
35
- <span>repo <code>${esc(repo)}</code></span>
36
- <span>template from <code>${esc(source)}</code></span>
37
- </div>`;
38
-
39
- if (result.verdict === 'unknown') {
40
- return meta + card('check', 'No chat template published',
41
- `<p>Nothing here can be decided from metadata. The repo publishes neither
42
- <code>chat_template.jinja</code> nor a <code>chat_template</code> in
43
- <code>tokenizer_config.json</code>, so there is no assistant turn to read.
44
- Serving it will still work — the decision just has to come from somewhere
45
- else.</p>`);
46
- }
47
-
48
- if (result.verdict === 'none') {
49
- return meta + card('clear', 'Serve it without a reasoning parser',
50
- `<div class="flag">vllm serve ${esc(repo)}</div>
51
- <p>The template carries no marker any parser closes on. Adding
52
- <code>--reasoning-parser</code> here is the silent failure: the parser
53
- would claim the whole answer, the request would finish with
54
- <code>stop</code>, and <code>content</code> would come back empty.</p>`);
55
- }
56
-
57
- const parsers = Object.keys(result.candidates).sort();
58
- // Parsers sharing one marker set are interchangeable for this model.
59
- // Naming the family one first is a convenience, not a rule the data
60
- // supports, so it is offered as a preference rather than a verdict.
61
- const preferred = parsers.find((p) => repo.toLowerCase().includes(p.split('_')[0]))
62
- || parsers[0];
63
- const marks = result.candidates[preferred];
64
-
65
- const others = parsers.filter((p) => p !== preferred);
66
- const alt = others.length
67
- ? `<p>Interchangeable for this model, because they close on the same marker:
68
- <code>${others.map(esc).join('</code>, <code>')}</code>. Pick the one named
69
- for the model's family if there is one.</p>`
70
- : '';
71
-
72
- return meta + card('check', 'This model thinks — it needs a parser',
73
- `<div class="flag">vllm serve ${esc(repo)} --reasoning-parser ${esc(preferred)}</div>
74
- <p>Its template emits ${marks.map((m) => `<code>${esc(m)}</code>`).join(' and ')},
75
- which <code>${esc(preferred)}</code> closes on.</p>
76
- ${alt}
77
- <p>Without the flag that section reaches the user as the answer.</p>`);
78
- }
79
-
80
- async function run(repo) {
81
- const go = $('go');
82
- go.disabled = true;
83
- out.innerHTML = `<p class="spin">reading ${esc(repo)}…</p>`;
84
- try {
85
- const { template, source } = await fetchTemplate(repo);
86
- out.innerHTML = render(repo, source, advise(template));
87
- } catch (e) {
88
- out.innerHTML = card('problem', 'Could not read the repo',
89
- `<p>${esc(e.message || e)}</p>
90
- <p>Gated and private repos cannot be read from the browser.</p>`);
91
- } finally {
92
- go.disabled = false;
93
- }
94
- }
95
-
96
- $('form').addEventListener('submit', (e) => {
97
- e.preventDefault();
98
- const v = $('repo').value.trim();
99
- if (v) run(v);
100
- });
101
- document.querySelectorAll('[data-ex]').forEach((b) =>
102
- b.addEventListener('click', () => {
103
- $('repo').value = b.dataset.ex;
104
- run(b.dataset.ex);
105
- }));
106
-
107
- renderRules();
 
 
 
 
 
 
 
1
+ /**
2
+ * The page: one repo id in, one serving decision out.
3
+ *
4
+ * All rules live in parser_advice.js, which the parity gate holds to the
5
+ * Python implementation. Nothing here decides anything — it fetches,
6
+ * calls, and renders, so a rule can never be quietly different in the UI
7
+ * from the one that was tested.
8
+ */
9
+ import { ALL_MARKERS, advise, fetchTemplate } from './parser_advice.js';
10
+ import { progress } from './progress.js';
11
+
12
+ const $ = (id) => document.getElementById(id);
13
+ const out = $('out');
14
+ const esc = (s) => String(s).replace(/[&<>"]/g, (c) =>
15
+ ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
16
+
17
+ function renderRules() {
18
+ const seen = new Map();
19
+ for (const [parser, marks] of Object.entries(ALL_MARKERS)) {
20
+ const key = marks.join(' ');
21
+ if (!seen.has(key)) seen.set(key, []);
22
+ seen.get(key).push(parser);
23
+ }
24
+ $('rules').innerHTML = [...seen.entries()].map(([marks, parsers]) =>
25
+ `<tr><td><code>${parsers.map(esc).join('</code>, <code>')}</code></td>` +
26
+ `<td><code>${marks.split(' ').map(esc).join('</code> <code>')}</code></td></tr>`
27
+ ).join('');
28
+ }
29
+
30
+ function card(cls, title, body) {
31
+ return `<div class="card ${cls}"><h3>${title}</h3>${body}</div>`;
32
+ }
33
+
34
+ function render(repo, source, result) {
35
+ const meta = `<div class="meta">
36
+ <span>repo <code>${esc(repo)}</code></span>
37
+ <span>template from <code>${esc(source)}</code></span>
38
+ </div>`;
39
+
40
+ if (result.verdict === 'unknown') {
41
+ return meta + card('check', 'No chat template published',
42
+ `<p>Nothing here can be decided from metadata. The repo publishes neither
43
+ <code>chat_template.jinja</code> nor a <code>chat_template</code> in
44
+ <code>tokenizer_config.json</code>, so there is no assistant turn to read.
45
+ Serving it will still work — the decision just has to come from somewhere
46
+ else.</p>`);
47
+ }
48
+
49
+ if (result.verdict === 'none') {
50
+ return meta + card('clear', 'Serve it without a reasoning parser',
51
+ `<div class="flag">vllm serve ${esc(repo)}</div>
52
+ <p>The template carries no marker any parser closes on. Adding
53
+ <code>--reasoning-parser</code> here is the silent failure: the parser
54
+ would claim the whole answer, the request would finish with
55
+ <code>stop</code>, and <code>content</code> would come back empty.</p>`);
56
+ }
57
+
58
+ const parsers = Object.keys(result.candidates).sort();
59
+ // Parsers sharing one marker set are interchangeable for this model.
60
+ // Naming the family one first is a convenience, not a rule the data
61
+ // supports, so it is offered as a preference rather than a verdict.
62
+ const preferred = parsers.find((p) => repo.toLowerCase().includes(p.split('_')[0]))
63
+ || parsers[0];
64
+ const marks = result.candidates[preferred];
65
+
66
+ const others = parsers.filter((p) => p !== preferred);
67
+ const alt = others.length
68
+ ? `<p>Interchangeable for this model, because they close on the same marker:
69
+ <code>${others.map(esc).join('</code>, <code>')}</code>. Pick the one named
70
+ for the model's family if there is one.</p>`
71
+ : '';
72
+
73
+ return meta + card('check', 'This model thinks — it needs a parser',
74
+ `<div class="flag">vllm serve ${esc(repo)} --reasoning-parser ${esc(preferred)}</div>
75
+ <p>Its template emits ${marks.map((m) => `<code>${esc(m)}</code>`).join(' and ')},
76
+ which <code>${esc(preferred)}</code> closes on.</p>
77
+ ${alt}
78
+ <p>Without the flag that section reaches the user as the answer.</p>`);
79
+ }
80
+
81
+ async function run(repo) {
82
+ const go = $('go');
83
+ go.disabled = true;
84
+ // Two small files at most, so this stays indeterminate — there is
85
+ // nothing to count. It is here for the same reason as on the other
86
+ // two pages: a page that shows nothing while it works reads as a page
87
+ // that does not work, and the wait is not always short.
88
+ const pg = progress(out).start(`reading the chat template of ${repo}`);
89
+ try {
90
+ const { template, source } = await fetchTemplate(repo);
91
+ pg.done();
92
+ out.innerHTML = render(repo, source, advise(template));
93
+ } catch (e) {
94
+ out.innerHTML = card('problem', 'Could not read the repo',
95
+ `<p>${esc(e.message || e)}</p>
96
+ <p>Gated and private repos cannot be read from the browser.</p>`);
97
+ } finally {
98
+ go.disabled = false;
99
+ }
100
+ }
101
+
102
+ $('form').addEventListener('submit', (e) => {
103
+ e.preventDefault();
104
+ const v = $('repo').value.trim();
105
+ if (v) run(v);
106
+ });
107
+ document.querySelectorAll('[data-ex]').forEach((b) =>
108
+ b.addEventListener('click', () => {
109
+ $('repo').value = b.dataset.ex;
110
+ run(b.dataset.ex);
111
+ }));
112
+
113
+ renderRules();
progress.js ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * The progress bar the three Spaces share.
3
+ *
4
+ * Every one of them reads safetensors headers over ranged requests — two
5
+ * per shard, and a large model has a dozen shards. That is seconds of
6
+ * silence behind a line of static text, which reads as a page that does
7
+ * not work. The bar exists so waiting looks like waiting.
8
+ *
9
+ * One file, copied into each Space at deploy time rather than written
10
+ * three times: three copies of a progress bar drift into three different
11
+ * behaviours, and the one that matters here is subtle — a bar that goes
12
+ * backwards, or sits at 100% while work continues, is worse than no bar,
13
+ * because it is believed.
14
+ *
15
+ * Two modes, and which one is honest depends on what is known:
16
+ *
17
+ * start(label) indeterminate — something is happening, and
18
+ * nobody knows how much of it there is yet
19
+ * total(n) switches to determinate once the shard count
20
+ * is known
21
+ * step(label) one unit done
22
+ * done() / fail() release it
23
+ */
24
+
25
+ const BAR_CSS = `
26
+ .pg { margin: 1.25rem 0 .5rem; }
27
+ .pg-label { font-size: .88rem; color: var(--muted); margin-bottom: .45rem;
28
+ display: flex; justify-content: space-between; gap: 1rem; }
29
+ .pg-count { font-family: var(--mono); font-size: .82rem; white-space: nowrap; }
30
+ .pg-track { height: .4rem; border-radius: .2rem; background: var(--line);
31
+ overflow: hidden; position: relative; }
32
+ .pg-fill { height: 100%; background: var(--accent); border-radius: .2rem;
33
+ width: 0; transition: width .18s ease-out; }
34
+ .pg-track.indeterminate .pg-fill {
35
+ width: 35%; animation: pg-slide 1.1s ease-in-out infinite;
36
+ }
37
+ @keyframes pg-slide {
38
+ 0% { transform: translateX(-100%); }
39
+ 100% { transform: translateX(300%); }
40
+ }
41
+ @media (prefers-reduced-motion: reduce) {
42
+ .pg-track.indeterminate .pg-fill { animation: none; width: 100%; opacity: .45; }
43
+ .pg-fill { transition: none; }
44
+ }`;
45
+
46
+ let styled = false;
47
+
48
+ function ensureStyle() {
49
+ if (styled) return;
50
+ const el = document.createElement('style');
51
+ el.textContent = BAR_CSS;
52
+ document.head.appendChild(el);
53
+ styled = true;
54
+ }
55
+
56
+ /**
57
+ * A progress bar mounted in `host`.
58
+ *
59
+ * It replaces the host's contents, so the caller renders the result into
60
+ * the same element when it finishes and the bar disappears with it.
61
+ */
62
+ export function progress(host) {
63
+ ensureStyle();
64
+ let done = 0;
65
+ let total = 0;
66
+
67
+ host.innerHTML = `<div class="pg">
68
+ <div class="pg-label"><span class="pg-text"></span><span class="pg-count"></span></div>
69
+ <div class="pg-track indeterminate"><div class="pg-fill"></div></div>
70
+ </div>`;
71
+
72
+ const text = host.querySelector('.pg-text');
73
+ const count = host.querySelector('.pg-count');
74
+ const track = host.querySelector('.pg-track');
75
+ const fill = host.querySelector('.pg-fill');
76
+
77
+ const paint = () => {
78
+ if (!total) return;
79
+ // Never let the bar reach the end before the work does: a full bar
80
+ // with the page still frozen is exactly the impression this is here
81
+ // to remove. It closes only in done().
82
+ const pctDone = Math.min(99, Math.round((done / total) * 100));
83
+ fill.style.width = `${pctDone}%`;
84
+ count.textContent = `${done} / ${total}`;
85
+ };
86
+
87
+ return {
88
+ /** Say what is happening now, without claiming to know how long. */
89
+ start(label) {
90
+ text.textContent = label;
91
+ return this;
92
+ },
93
+ /**
94
+ * Begin a determinate phase of `n` units.
95
+ *
96
+ * Resets the count, because a second call means a second phase — the
97
+ * integrity checker reads the pack and then the source model, and
98
+ * without the reset the bar would show "12 / 5" and run past its own
99
+ * end.
100
+ */
101
+ total(n) {
102
+ total = n;
103
+ done = 0;
104
+ track.classList.remove('indeterminate');
105
+ paint();
106
+ return this;
107
+ },
108
+ /** One unit finished. Safe to call before total() — it just counts. */
109
+ step(label) {
110
+ done += 1;
111
+ if (label) text.textContent = label;
112
+ paint();
113
+ return this;
114
+ },
115
+ /** Fill it before the caller replaces the host with the result. */
116
+ done() {
117
+ track.classList.remove('indeterminate');
118
+ fill.style.width = '100%';
119
+ if (total) count.textContent = `${total} / ${total}`;
120
+ return this;
121
+ },
122
+ };
123
+ }