Spaces:
Paused
Paused
matt HOFFNER
commited on
Commit
·
8e0db75
1
Parent(s):
7a6cf6a
try again
Browse files- src/app/search/web/page.jsx +18 -13
src/app/search/web/page.jsx
CHANGED
|
@@ -27,25 +27,31 @@ export default function WebSearchPage({ searchParams }) {
|
|
| 27 |
} else {
|
| 28 |
const reader = response.body.getReader();
|
| 29 |
const decoder = new TextDecoder();
|
| 30 |
-
let
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
return reader.read().then(function processText({ done, value }) {
|
| 33 |
if (done) {
|
| 34 |
-
|
| 35 |
try {
|
| 36 |
-
json = JSON.parse(
|
|
|
|
|
|
|
|
|
|
| 37 |
} catch (error) {
|
| 38 |
console.error("Failed to parse JSON", error);
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
console.log(json);
|
| 42 |
-
setAiResponse(json);
|
| 43 |
-
console.log("Stream complete");
|
| 44 |
-
return;
|
| 45 |
}
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
}
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
|
@@ -55,7 +61,6 @@ export default function WebSearchPage({ searchParams }) {
|
|
| 55 |
|
| 56 |
return () => controller.abort();
|
| 57 |
}, [searchParams, searchTerm]);
|
| 58 |
-
|
| 59 |
|
| 60 |
|
| 61 |
console.log(aiResponse);
|
|
|
|
| 27 |
} else {
|
| 28 |
const reader = response.body.getReader();
|
| 29 |
const decoder = new TextDecoder();
|
| 30 |
+
let text = '';
|
| 31 |
+
|
| 32 |
+
while (true) {
|
| 33 |
+
if (stopConversationRef.current === true) {
|
| 34 |
+
controller.abort();
|
| 35 |
+
break;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
const { value, done } = await reader.read();
|
| 39 |
|
|
|
|
| 40 |
if (done) {
|
| 41 |
+
// When the stream ends, we can parse the complete text
|
| 42 |
try {
|
| 43 |
+
const json = JSON.parse(text);
|
| 44 |
+
console.log(json);
|
| 45 |
+
setAiResponse(json);
|
| 46 |
+
console.log("Stream complete");
|
| 47 |
} catch (error) {
|
| 48 |
console.error("Failed to parse JSON", error);
|
| 49 |
}
|
| 50 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
+
|
| 53 |
+
text += decoder.decode(value);
|
| 54 |
+
}
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
|
|
|
| 61 |
|
| 62 |
return () => controller.abort();
|
| 63 |
}, [searchParams, searchTerm]);
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
console.log(aiResponse);
|