-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsummarize.js
More file actions
39 lines (34 loc) · 997 Bytes
/
Copy pathsummarize.js
File metadata and controls
39 lines (34 loc) · 997 Bytes
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
// This is the function where the call to the API is made. Returns the summarized text as a string.
const axios = require('axios');
require('dotenv').config();
async function summarizeText(text) {
console.log("Summarizing..\n");
// INSERT CODE SNIPPET FROM POSTMAN BELOW
let data = JSON.stringify({
"inputs": text,
"parameters": {
"max_length": 1500,
"min_length": 30
}
});
console.log("ENV ", process.env.ACCESS_TOKEN);
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api-inference.huggingface.co/models/facebook/bart-large-cnn',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + process.env.ACCESS_TOKEN
},
data: data
};
try {
const response = await axios.request(config);
return response.data[0].summary_text;
}
catch (error) {
console.log(error);
}
}
// Allows for summarizeText() to be called outside of this file
module.exports = summarizeText;