-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize.js
45 lines (33 loc) · 1.1 KB
/
summarize.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Axios is the framework we will be using to calling the API
const axios = require('axios');
// This is the function where the call to the API is made. Returns the summarized text as a string.
async function summarizeText(text) {
// INSERT CODE SNIPPET FROM POSTMAN BELOW
let data = JSON.stringify({
"inputs": text,
"parameters": {
"max_length": 100,
"min_length": 30
}
});
// A config object that will contain the instructions for the API call
let config = {
method: 'post',
url: 'https://api-inference.huggingface.co/models/facebook/bart-large-cnn',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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'
},
data: data
};
// Capture the request in a try/catch to check for any errors that may occur
try {
const response = await axios.request(config);
// Return the summary text from the response
return response.data[0].summary_text;
} catch (err) {
console.log(err);
}
}
// Allows for summarizeText() to be called outside of this file
module.exports = summarizeText;