Iinitial value from -1 to null, better calculation

73d4922d70b2720faf7937ba22a046fc9064a234

bmen25124 <bmen25124@gmail.com>

1 files changed, +11 -6Ignore whitespace
public/script.js+11 -6
@@ -2597,7 +2597,7 @@ export function formatCharacterAvatar(characterAvatar) {
25972597 * @param {Date} gen_started Date when generation was started
25982598 * @param {Date} gen_finished Date when generation was finished
25992599 * @param {number} tokenCount Number of tokens generated (0 if not available)
26002600 * @param {number | null} timeToFirstToken Time to first token
26012601 * @param {number?} [reasoningDuration=null] Reasoning duration (null if no reasoning was done)
26022602 * @returns {Object} Object containing the formatted timer value and title
26032603 * @example
@@ -2619,7 +2619,7 @@ function formatGenerationTimer(gen_started, gen_finished, tokenCount, timeToFirs
26192619 `Generation queued: ${start.format(dateFormat)}`,
26202620 `Reply received: ${finish.format(dateFormat)}`,
26212621 `Time to generate: ${seconds} seconds`,
26222622 timeToFirstToken > 0 ? `Time to first token: ${(timeToFirstToken / 1000).toFixed(1)} seconds` : '',
26232623 reasoningDuration > 0 ? `Time to think: ${reasoningDuration / 1000} seconds` : '',
26242624 tokenCount > 0 ? `Token rate: ${Number(tokenCount / seconds).toFixed(1)} t/s` : '',
26252625 ].filter(x => x).join('\n').trim();
@@ -3160,7 +3160,10 @@ class StreamingProcessor {
31603160 this.abortController = new AbortController();
31613161 this.firstMessageText = '...';
31623162 this.timeStarted = timeStarted;
3163- this.timeToFirstToken = -1;
3163+ /**
3164+ * @type {number | null}
3165+ */
3166+ this.timeToFirstToken = null;
31643167 this.createdAt = new Date();
31653168 this.continueMessage = type === 'continue' ? continueMessage : '';
31663169 this.swipes = [];
@@ -3199,8 +3202,6 @@ class StreamingProcessor {
31993202 }
32003203
32013204 async onStartStreaming(text) {
3202- this.timeToFirstToken = Date.now() - this.createdAt.getTime();
3203-
32043205 if (this.type === 'continue' && this.promptReasoning.prefixReasoning) {
32053206 this.reasoningHandler.initContinue(this.promptReasoning);
32063207 }
@@ -3409,7 +3410,11 @@ class StreamingProcessor {
34093410 const sw = new Stopwatch(1000 / power_user.streaming_fps);
34103411 const timestamps = [];
34113412 for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) {
34123413 timestamps.push(const now = Date.now());
3414+ timestamps.push(now);
3415+ if (!this.timeToFirstToken) {
3416+ this.timeToFirstToken = now - this.createdAt.getTime();
3417+ }
34133418 if (this.isStopped || this.abortController.signal.aborted) {
34143419 return this.result;
34153420 }