First draft of toxic-comments

This commit is contained in:
Chi Vinh Le
2017-09-06 22:11:48 +07:00
parent fea5f75aa6
commit 6f82fd76f5
32 changed files with 298 additions and 491 deletions
@@ -0,0 +1,37 @@
const fetch = require('node-fetch');
const API_ENPOINT = 'https://commentanalyzer.googleapis.com/v1alpha1';
async function getScores(apiKey, text) {
const response = await fetch(`${API_ENPOINT}/comments:analyze?key=${apiKey}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
comment: {
text,
},
// TODO: support other languages.
languages: ['en'],
requestedAttributes: {
TOXICITY: {},
SEVERE_TOXICITY: {},
}
}),
});
const data = await response.json();
return {
TOXICITY: {
summaryScore: data.attributeScores.TOXICITY.summaryScore.value
},
SEVERE_TOXICITY: {
summaryScore: data.attributeScores.SEVERE_TOXICITY.summaryScore.value
},
};
}
module.exports = {
getScores,
};