Spaces:
Paused
Paused
matt HOFFNER
commited on
Commit
·
a4ebd61
1
Parent(s):
ff2cd25
try again
Browse files- src/app/search/web/page.jsx +14 -16
src/app/search/web/page.jsx
CHANGED
@@ -26,24 +26,22 @@ export default function WebSearchPage({ searchParams }) {
|
|
26 |
throw new Error(`HTTP error! status: ${response.status}`);
|
27 |
} else {
|
28 |
const reader = response.body.getReader();
|
29 |
-
|
30 |
-
let text = '';
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
try {
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
if (done) {
|
37 |
-
// When the stream ends, we can parse the complete text
|
38 |
-
const json = JSON.parse(text);
|
39 |
-
console.log(json);
|
40 |
-
setAiResponse(json);
|
41 |
-
console.log("Stream complete");
|
42 |
-
break;
|
43 |
-
}
|
44 |
-
|
45 |
-
text += decoder.decode(value, {stream: true});
|
46 |
-
}
|
47 |
} catch (error) {
|
48 |
console.error("Failed to parse JSON", error);
|
49 |
}
|
|
|
26 |
throw new Error(`HTTP error! status: ${response.status}`);
|
27 |
} else {
|
28 |
const reader = response.body.getReader();
|
29 |
+
let chunks = [];
|
|
|
30 |
|
31 |
+
while (true) {
|
32 |
+
const { done, value } = await reader.read();
|
33 |
+
|
34 |
+
if (done) break;
|
35 |
+
|
36 |
+
chunks.push(value);
|
37 |
+
}
|
38 |
+
|
39 |
+
const text = new TextDecoder().decode(new Uint8Array(chunks.flat()));
|
40 |
+
|
41 |
try {
|
42 |
+
const json = JSON.parse(text);
|
43 |
+
console.log(json);
|
44 |
+
setAiResponse(json);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
} catch (error) {
|
46 |
console.error("Failed to parse JSON", error);
|
47 |
}
|