Spaces:
Paused
Paused
matt HOFFNER
commited on
Commit
·
79f1edc
1
Parent(s):
d73f75f
simplify
Browse files- src/app/search/web/page.jsx +5 -14
src/app/search/web/page.jsx
CHANGED
|
@@ -11,8 +11,6 @@ export default function WebSearchPage({ searchParams }) {
|
|
| 11 |
}, [searchParams])
|
| 12 |
|
| 13 |
useEffect(() => {
|
| 14 |
-
const decoder = new TextDecoder();
|
| 15 |
-
let responseText = '';
|
| 16 |
const controller = new AbortController();
|
| 17 |
const signal = controller.signal;
|
| 18 |
|
|
@@ -23,24 +21,17 @@ export default function WebSearchPage({ searchParams }) {
|
|
| 23 |
body: JSON.stringify({ question: searchTerm || "Seattle activities this weekend" }),
|
| 24 |
signal,
|
| 25 |
});
|
| 26 |
-
const reader = response.body.getReader();
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
}
|
| 33 |
-
responseText += decoder.decode(value);
|
| 34 |
-
console.log(responseText);
|
| 35 |
-
setAiResponse(responseText);
|
| 36 |
-
return reader.read().then(processText);
|
| 37 |
-
});
|
| 38 |
}
|
| 39 |
|
| 40 |
fetchData();
|
| 41 |
|
| 42 |
return () => controller.abort();
|
| 43 |
-
}, [searchParams, searchTerm]);
|
| 44 |
|
| 45 |
console.log(aiResponse);
|
| 46 |
|
|
|
|
| 11 |
}, [searchParams])
|
| 12 |
|
| 13 |
useEffect(() => {
|
|
|
|
|
|
|
| 14 |
const controller = new AbortController();
|
| 15 |
const signal = controller.signal;
|
| 16 |
|
|
|
|
| 21 |
body: JSON.stringify({ question: searchTerm || "Seattle activities this weekend" }),
|
| 22 |
signal,
|
| 23 |
});
|
|
|
|
| 24 |
|
| 25 |
+
// Use .json() to parse the JSON response
|
| 26 |
+
const responseData = await response.json();
|
| 27 |
+
console.log(responseData);
|
| 28 |
+
setAiResponse(responseData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
fetchData();
|
| 32 |
|
| 33 |
return () => controller.abort();
|
| 34 |
+
}, [searchParams, searchTerm]);
|
| 35 |
|
| 36 |
console.log(aiResponse);
|
| 37 |
|