nsarrazin HF staff commited on
Commit
c1caa1f
1 Parent(s): 2435b95

Send characters by groups of 5 (#1007)

Browse files

* Send characters by groups of 5

* remove comment

src/routes/conversation/[id]/+server.ts CHANGED
@@ -422,15 +422,16 @@ export async function POST({ request, locals, params, getClientAddress }) {
422
  // if not generated_text is here it means the generation is not done
423
  if (!output.generated_text) {
424
  if (!output.token.special) {
425
- // 33% chance to send the stream update, with a max buffer size of 30 chars
426
  buffer += output.token.text;
427
 
428
- if (Math.random() < 0.33 || buffer.length > 30) {
 
 
429
  update({
430
  type: "stream",
431
- token: buffer,
432
  });
433
- buffer = "";
434
  }
435
 
436
  // abort check
 
422
  // if not generated_text is here it means the generation is not done
423
  if (!output.generated_text) {
424
  if (!output.token.special) {
 
425
  buffer += output.token.text;
426
 
427
+ // send the first 5 chars
428
+ // and leave the rest in the buffer
429
+ if (buffer.length >= 5) {
430
  update({
431
  type: "stream",
432
+ token: buffer.slice(0, 5),
433
  });
434
+ buffer = buffer.slice(5);
435
  }
436
 
437
  // abort check