-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (33 loc) 路 1.21 KB
/
Copy pathscript.js
File metadata and controls
41 lines (33 loc) 路 1.21 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
async function generateSummary() {
const text = document.getElementById("inputText").value;
const output = document.getElementById("output");
const API_KEY = "AIzaSy*********************pate you api key";
try {
const response = await fetch(
"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=" + API_KEY,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
contents: [{
parts: [{
text: "Summarize this text: " + text
}]
}]
})
}
);
const data = await response.json();
console.log(data); // 馃敟 Debug line
if (data.candidates) {
output.innerText = data.candidates[0].content.parts[0].text;
} else {
output.innerText = "Error generating summary.";
}
} catch (error) {
console.error(error);
output.innerText = "Something went wrong!";
}
}