-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
43 lines (37 loc) · 1.05 KB
/
background.js
File metadata and controls
43 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
chrome.runtime.onInstalled.addListener(() => {
console.log("AI Installation Done!");
// Initialize extension settings
chrome.storage.local.set({
isEnabled: true,
scrollInterval: 2000,
scrollDistance: 100,
});
});
// Listen for messages from content script
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "log") {
console.log(request.message);
}
return true;
});
async function fetchAIResponse(question) {
try {
const response = await fetch("https://your-deployed-server.com/api/ask", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
messages: [{ role: "user", content: question }],
}),
});
if (!response.ok) {
throw new Error(`Server error: ${response.status}`);
}
const data = await response.json();
return data.choices[0].message.content;
} catch (error) {
console.error("Error fetching AI response:", error);
return "Error fetching response.";
}
}