Skip to content

Commit c1caa1f

Browse files
authored
Send characters by groups of 5 (#1007)
* Send characters by groups of 5 * remove comment
1 parent 2435b95 commit c1caa1f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/routes/conversation/[id]/+server.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,16 @@ export async function POST({ request, locals, params, getClientAddress }) {
422422
// if not generated_text is here it means the generation is not done
423423
if (!output.generated_text) {
424424
if (!output.token.special) {
425-
// 33% chance to send the stream update, with a max buffer size of 30 chars
426425
buffer += output.token.text;
427426

428-
if (Math.random() < 0.33 || buffer.length > 30) {
427+
// send the first 5 chars
428+
// and leave the rest in the buffer
429+
if (buffer.length >= 5) {
429430
update({
430431
type: "stream",
431-
token: buffer,
432+
token: buffer.slice(0, 5),
432433
});
433-
buffer = "";
434+
buffer = buffer.slice(5);
434435
}
435436

436437
// abort check

0 commit comments

Comments
 (0)