-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
23 lines (19 loc) · 871 Bytes
/
Copy pathcontent.js
File metadata and controls
23 lines (19 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
async function sendTextToBackend(webpageText, userQuestion) {
try {
console.log("📤 Sending data to Flask:", { question: userQuestion });
const response = await fetch("http://127.0.0.1:5000/answer", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: webpageText, question: userQuestion }) // ✅ No context
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
console.log("📥 Response from Flask:", data);
// ✅ Show only question & answer
alert(`📝 Question: ${data.question}\n💡 Answer: ${data.answer}`);
} catch (error) {
console.error("❌ Error sending request:", error);
}
}