mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Toxic Comments Plugin logging (#1970)
* Add debug as a dep to toxic-comments * Add debug logging to toxic-comments plugin * fix: cleaned up a bit
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"author": "The Coral Project Team <coral@mozillafoundation.org>",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"debug": "^4.0.1",
|
||||
"ms": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { getScores, isToxic } = require('./perspective');
|
||||
const { ErrToxic } = require('./errors');
|
||||
const debug = require('debug')('talk:plugin:toxic-comments');
|
||||
|
||||
function handlePositiveToxic(input) {
|
||||
input.status = 'SYSTEM_WITHHELD';
|
||||
@@ -20,7 +21,7 @@ async function getScore(body) {
|
||||
scores = await getScores(body);
|
||||
} catch (err) {
|
||||
// Warn and let mutation pass.
|
||||
console.trace(err); // TODO: log/handle this differently?
|
||||
debug('Error sending to API: %o', err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ const {
|
||||
API_TIMEOUT,
|
||||
DO_NOT_STORE,
|
||||
} = require('./config');
|
||||
const debug = require('debug')('talk:plugin:toxic-comments');
|
||||
|
||||
/**
|
||||
* Get scores from the perspective api
|
||||
@@ -13,6 +14,8 @@ const {
|
||||
* @return {object} object containing toxicity scores
|
||||
*/
|
||||
async function getScores(text) {
|
||||
debug('Sending to Perspective: %o', text);
|
||||
|
||||
const response = await fetch(
|
||||
`${API_ENDPOINT}/comments:analyze?key=${API_KEY}`,
|
||||
{
|
||||
@@ -25,7 +28,6 @@ async function getScores(text) {
|
||||
comment: {
|
||||
text,
|
||||
},
|
||||
|
||||
// TODO: support other languages.
|
||||
languages: ['en'],
|
||||
doNotStore: DO_NOT_STORE,
|
||||
@@ -36,7 +38,22 @@ async function getScores(text) {
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// If we get an error, just say it's not a toxic comment.
|
||||
if (data.error) {
|
||||
debug('Recieved Error when submitting: %o', data.error);
|
||||
return {
|
||||
TOXICITY: {
|
||||
summaryScore: 0.0,
|
||||
},
|
||||
SEVERE_TOXICITY: {
|
||||
summaryScore: 0.0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
TOXICITY: {
|
||||
summaryScore: data.attributeScores.TOXICITY.summaryScore.value,
|
||||
|
||||
Reference in New Issue
Block a user