Hansimov commited on
Commit
436c8c4
1 Parent(s): 3ab87cd

:boom: [Fix] Unable to parse broken chunks in same line

Browse files
Files changed (1) hide show
  1. networks/llm_requester.js +9 -4
networks/llm_requester.js CHANGED
@@ -80,14 +80,19 @@ export class ChatCompletionsRequester {
80
  .then((response) => response.body)
81
  .then((rb) => {
82
  const reader = rb.getReader();
 
83
  return reader.read().then(function process({ done, value }) {
84
  if (done) {
85
  return;
86
  }
87
- let json_chunks = jsonize_stream_data(
88
- stringify_stream_bytes(value)
89
- );
90
- update_message(json_chunks);
 
 
 
 
91
  return reader.read().then(process);
92
  });
93
  })
 
80
  .then((response) => response.body)
81
  .then((rb) => {
82
  const reader = rb.getReader();
83
+ let buffer = "";
84
  return reader.read().then(function process({ done, value }) {
85
  if (done) {
86
  return;
87
  }
88
+ buffer += stringify_stream_bytes(value);
89
+ let boundary = buffer.lastIndexOf("\n");
90
+ if (boundary !== -1) {
91
+ let input = buffer.substring(0, boundary);
92
+ buffer = buffer.substring(boundary + 1);
93
+ let json_chunks = jsonize_stream_data(input);
94
+ update_message(json_chunks);
95
+ }
96
  return reader.read().then(process);
97
  });
98
  })