okami.mom/strata

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

Niko1221merge f-split-fr (owner app UI fixes, rounds 1-5) into f-split-int8820fa433

main
2.2 KiB40 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { createServer } from 'node:http';
4import { proxyCompletion } from '../server/inference.mjs';
5
6/* The speed shown while an answer streams must be the decode speed of everything generated, reasoning included, from the first
7   token (the owner saw 4-5 tok/s in chat while the engine log said 48-57): the stand-in engine streams 90 reasoning tokens at about
8   40 a second, a 4 s "prompt" before the first one, then a short answer. */
9function engine({ promptMs, reasoning, answer, perSecond }) {
10  return createServer((req, res) => {
11    res.writeHead(200, { 'content-type': 'text/event-stream' });
12    const send = obj => res.write(`data: ${JSON.stringify(obj)}\n\n`);
13    let sent = 0;
14    setTimeout(function tick() {
15      if (sent < reasoning + answer) {
16        send({ choices: [{ delta: sent < reasoning ? { reasoning_content: 'tok ' } : { content: 'ans ' } }] });
17        sent++;
18        return setTimeout(tick, 1000 / perSecond);
19      }
20      send({ choices: [], usage: { prompt_tokens: 20, completion_tokens: reasoning + answer } });
21      res.write('data: [DONE]\n\n'); res.end();
22    }, promptMs);
23  });
24}
25
26test('live speed counts reasoning tokens over decode time, not the answer over the whole wait', async () => {
27  const server = engine({ promptMs: 4000, reasoning: 90, answer: 10, perSecond: 40 });
28  await new Promise(r => server.listen(0, '127.0.0.1', r));
29  const frames = [];
30  try {
31    const result = await proxyCompletion({ baseUrl: `http://127.0.0.1:${server.address().port}/v1`, message: 'hi', onFrame: f => frames.push(f), engine: { beginReading() {}, beginThinking() {}, beginGenerating() {} } });
32    const stats = frames.filter(f => f.type === 'stats');
33    assert.ok(stats.length >= 2, 'live frames while it streams');
34    const last = stats.at(-1);
35    assert.ok(last.tps > 22 && last.tps < 80, `live tok/s ${last.tps} is the decode rate, not tokens over the wait including the prompt (~14)`);
36    assert.ok(last.tokensOut >= 50, 'reasoning tokens are counted');
37    assert.equal(result.tokensOut, 100);
38    assert.ok(result.tps > 22 && result.tps < 80, `final tok/s ${result.tps}`);
39  } finally { server.close(); }
40});