Browse Source

feat-sse-calls-counter-in-meta

master
Serge Shutov 2 weeks ago
parent
commit
208a1a6425
  1. 7
      injected/chat-logger.js

7
injected/chat-logger.js

@ -168,9 +168,8 @@ @@ -168,9 +168,8 @@
if (req && Array.isArray(req.messages)) messages = req.messages
else if (req && typeof req.prompt === 'string' && req.prompt) messages = [{ role: 'user', content: req.prompt }]
} catch (e) { return }
var assistant = ''
try { assistant = extractAssistant(entry.resp || '') } catch (e) { }
var all = messages.slice()
var assistant = ''; var sseCalls = 0
try { assistant = extractAssistant(entry.resp || '') } catch (e) { }; try { var LB1 = String.fromCharCode(10214); var RB1 = String.fromCharCode(10215); var marker = LB1 + 'DSH' + RB1; var pos = 0; while (true) { var hit = assistant.indexOf(marker, pos); if (hit === -1) break; sseCalls = sseCalls + 1; pos = hit + marker.length } } catch (e) { } var all = messages.slice()
if (assistant) all.push({ role: 'assistant', content: assistant })
var file = today() + '.jsonl'
var lines = []
@ -207,7 +206,7 @@ @@ -207,7 +206,7 @@
accum: accum,
delta: delta,
chars: ctxChars,
chat_id: chatId, parent_id: pid, req_keys: reqKeys, est_tok: Math.round(ctxChars / K_RATIO), ctx_chars: charsAccum, ctx_tok: Math.round(charsAccum / K_RATIO), ctx_pct: Math.round(charsAccum / K_RATIO * 1000 / CONTEXT_LIMIT) / 10
chat_id: chatId, parent_id: pid, sse_calls: sseCalls, req_keys: reqKeys, est_tok: Math.round(ctxChars / K_RATIO), ctx_chars: charsAccum, ctx_tok: Math.round(charsAccum / K_RATIO), ctx_pct: Math.round(charsAccum / K_RATIO * 1000 / CONTEXT_LIMIT) / 10
}
lines.push(JSON.stringify(meta)); try { window.dispatchEvent(new CustomEvent('dshmem:metrics', { detail: JSON.stringify({ accum: accum, delta: delta, chars: ctxChars, est_tok: Math.round(ctxChars / K_RATIO), ctx_chars: charsAccum, ctx_tok: Math.round(charsAccum / K_RATIO), ctx_pct: Math.round(charsAccum / K_RATIO * 1000 / CONTEXT_LIMIT) / 10 }) })) } catch (e) { }
}

Loading…
Cancel
Save