Iinitial value from -1 to null, better calculation
| @@ -2597,7 +2597,7 @@ export function formatCharacterAvatar(characterAvatar) { | |||
| 2597 | * @param {Date} gen_started Date when generation was started | 2597 | * @param {Date} gen_started Date when generation was started |
| 2598 | * @param {Date} gen_finished Date when generation was finished | 2598 | * @param {Date} gen_finished Date when generation was finished |
| 2599 | * @param {number} tokenCount Number of tokens generated (0 if not available) | 2599 | * @param {number} tokenCount Number of tokens generated (0 if not available) |
| 2600 | * @param {number} timeToFirstToken Time to first token | 2600 | * @param {number | null} timeToFirstToken Time to first token |
| 2601 | * @param {number?} [reasoningDuration=null] Reasoning duration (null if no reasoning was done) | 2601 | * @param {number?} [reasoningDuration=null] Reasoning duration (null if no reasoning was done) |
| 2602 | * @returns {Object} Object containing the formatted timer value and title | 2602 | * @returns {Object} Object containing the formatted timer value and title |
| 2603 | * @example | 2603 | * @example |
| @@ -2619,7 +2619,7 @@ function formatGenerationTimer(gen_started, gen_finished, tokenCount, timeToFirs | |||
| 2619 | `Generation queued: ${start.format(dateFormat)}`, | 2619 | `Generation queued: ${start.format(dateFormat)}`, |
| 2620 | `Reply received: ${finish.format(dateFormat)}`, | 2620 | `Reply received: ${finish.format(dateFormat)}`, |
| 2621 | `Time to generate: ${seconds} seconds`, | 2621 | `Time to generate: ${seconds} seconds`, |
| 2622 | timeToFirstToken > 0 ? `Time to first token: ${(timeToFirstToken / 1000).toFixed(1)} seconds` : '', | 2622 | timeToFirstToken ? `Time to first token: ${(timeToFirstToken / 1000).toFixed(1)} seconds` : '', |
| 2623 | reasoningDuration > 0 ? `Time to think: ${reasoningDuration / 1000} seconds` : '', | 2623 | reasoningDuration > 0 ? `Time to think: ${reasoningDuration / 1000} seconds` : '', |
| 2624 | tokenCount > 0 ? `Token rate: ${Number(tokenCount / seconds).toFixed(1)} t/s` : '', | 2624 | tokenCount > 0 ? `Token rate: ${Number(tokenCount / seconds).toFixed(1)} t/s` : '', |
| 2625 | ].filter(x => x).join('\n').trim(); | 2625 | ].filter(x => x).join('\n').trim(); |
| @@ -3160,7 +3160,10 @@ class StreamingProcessor { | |||
| 3160 | this.abortController = new AbortController(); | 3160 | this.abortController = new AbortController(); |
| 3161 | this.firstMessageText = '...'; | 3161 | this.firstMessageText = '...'; |
| 3162 | this.timeStarted = timeStarted; | 3162 | this.timeStarted = timeStarted; |
| 3163 | this.timeToFirstToken = -1; | 3163 | /** |
| 3164 | * @type {number | null} | ||
| 3165 | */ | ||
| 3166 | this.timeToFirstToken = null; | ||
| 3164 | this.createdAt = new Date(); | 3167 | this.createdAt = new Date(); |
| 3165 | this.continueMessage = type === 'continue' ? continueMessage : ''; | 3168 | this.continueMessage = type === 'continue' ? continueMessage : ''; |
| 3166 | this.swipes = []; | 3169 | this.swipes = []; |
| @@ -3199,8 +3202,6 @@ class StreamingProcessor { | |||
| 3199 | } | 3202 | } |
| 3200 | 3203 | ||
| 3201 | async onStartStreaming(text) { | 3204 | async onStartStreaming(text) { |
| 3202 | this.timeToFirstToken = Date.now() - this.createdAt.getTime(); | ||
| 3203 | |||
| 3204 | if (this.type === 'continue' && this.promptReasoning.prefixReasoning) { | 3205 | if (this.type === 'continue' && this.promptReasoning.prefixReasoning) { |
| 3205 | this.reasoningHandler.initContinue(this.promptReasoning); | 3206 | this.reasoningHandler.initContinue(this.promptReasoning); |
| 3206 | } | 3207 | } |
| @@ -3409,7 +3410,11 @@ class StreamingProcessor { | |||
| 3409 | const sw = new Stopwatch(1000 / power_user.streaming_fps); | 3410 | const sw = new Stopwatch(1000 / power_user.streaming_fps); |
| 3410 | const timestamps = []; | 3411 | const timestamps = []; |
| 3411 | for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) { | 3412 | for await (const { text, swipes, logprobs, toolCalls, state } of this.generator()) { |
| 3412 | timestamps.push(Date.now()); | 3413 | const now = Date.now(); |
| 3414 | timestamps.push(now); | ||
| 3415 | if (!this.timeToFirstToken) { | ||
| 3416 | this.timeToFirstToken = now - this.createdAt.getTime(); | ||
| 3417 | } | ||
| 3413 | if (this.isStopped || this.abortController.signal.aborted) { | 3418 | if (this.isStopped || this.abortController.signal.aborted) { |
| 3414 | return this.result; | 3419 | return this.result; |
| 3415 | } | 3420 | } |