-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (29 loc) · 1.03 KB
/
index.js
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
async function getSummary(){
const text=document.getElementById('text').value;
console.log(text);
const requestBody={
text:text.toString(),
min_length:100,
max_length:300,
};
try{
const response = await fetch('https://tldrthis.p.rapidapi.com/v1/model/abstractive/summarize-text/',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-rapidapi-key': '$API_KEY',
'x-rapidapi-host': 'tldrthis.p.rapidapi.com'
},
body: JSON.stringify(requestBody)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const result = await response.json(); // Assuming the response is JSON, use response.text() if it's plain text
console.log(result);
const set = document.getElementById("summary");
set.innerText = result.summary.toString();
}catch (e){
console.log(e);
}
}