Merge pull request #2745 from SillyTavern/stream-tick-event Emit event on streaming tick

825fb3706e469805066adf561d50abc5df890e0a

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
2 files changed, +4 -3Ignore whitespace
public/script.js+4 -1
@@ -454,7 +454,9 @@ export const event_types = {
454 // TODO: Naming convention is inconsistent with other events454 // TODO: Naming convention is inconsistent with other events
455 CHARACTER_DELETED: 'characterDeleted',455 CHARACTER_DELETED: 'characterDeleted',
456 CHARACTER_DUPLICATED: 'character_duplicated',456 CHARACTER_DUPLICATED: 'character_duplicated',
457 SMOOTH_STREAM_TOKEN_RECEIVED: 'smooth_stream_token_received',457 /** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */
458 SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',
459 STREAM_TOKEN_RECEIVED: 'stream_token_received',
458 FILE_ATTACHMENT_DELETED: 'file_attachment_deleted',460 FILE_ATTACHMENT_DELETED: 'file_attachment_deleted',
459 WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate',461 WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate',
460 OPEN_CHARACTER_LIBRARY: 'open_character_library',462 OPEN_CHARACTER_LIBRARY: 'open_character_library',
@@ -3122,6 +3124,7 @@ class StreamingProcessor {
3122 if (logprobs) {3124 if (logprobs) {
3123 this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));3125 this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));
3124 }3126 }
3127 await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text);
3125 await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text));3128 await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text));
3126 }3129 }
3127 const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000;3130 const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000;
public/scripts/sse-stream.js+0 -2
@@ -1,4 +1,3 @@
1import { eventSource, event_types } from '../script.js';
2import { power_user } from './power-user.js';1import { power_user } from './power-user.js';
3import { delay } from './utils.js';2import { delay } from './utils.js';
43
@@ -268,7 +267,6 @@ export class SmoothEventSourceStream extends EventSourceStream {
268 hasFocus && await delay(getDelay(lastStr));267 hasFocus && await delay(getDelay(lastStr));
269 controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) }));268 controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) }));
270 lastStr = parsed.chunk;269 lastStr = parsed.chunk;
271 hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk);
272 }270 }
273 } catch (error) {271 } catch (error) {
274 console.debug('Smooth Streaming parsing error', error);272 console.debug('Smooth Streaming parsing error', error);