Hansimov commited on
Commit
2a37cd6
1 Parent(s): f7c1f6c

:boom: [Fix] Same line broken into multiple chunks

Browse files
Files changed (1) hide show
  1. networks/stream_jsonizer.js +6 -2
networks/stream_jsonizer.js CHANGED
@@ -6,6 +6,7 @@ export function stringify_stream_bytes(bytes) {
6
 
7
  export function jsonize_stream_data(data) {
8
  var json_chunks = [];
 
9
  data = data
10
  .replace(/^data:\s*/gm, "")
11
  .replace(/\[DONE\]/gm, "")
@@ -15,9 +16,12 @@ export function jsonize_stream_data(data) {
15
  })
16
  .map(function (line) {
17
  try {
18
- // ToFix: Single line broken into multiple chunks
19
- json_chunks.push(JSON.parse(line.trim()));
 
 
20
  } catch {
 
21
  console.log(`Failed to parse: ${line}`);
22
  }
23
  });
 
6
 
7
  export function jsonize_stream_data(data) {
8
  var json_chunks = [];
9
+ var buffer = ""
10
  data = data
11
  .replace(/^data:\s*/gm, "")
12
  .replace(/\[DONE\]/gm, "")
 
16
  })
17
  .map(function (line) {
18
  try {
19
+ // TODO: Single line broken into multiple chunks
20
+ let json_chunk = JSON.parse(line.trim());
21
+ json_chunks.push(json_chunk);
22
+ buffer = ""
23
  } catch {
24
+ buffer += line;
25
  console.log(`Failed to parse: ${line}`);
26
  }
27
  });