diff --git a/jspp.js b/jspp.js index d26ef8c..61677e9 100644 --- a/jspp.js +++ b/jspp.js @@ -9,7 +9,28 @@ class JSPlusPlus { sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } - + + function isToxic(sentences) { + let gen = new JSPlusPlus.General + // Load the model. Users optionally pass in a threshold and an array of + // labels to include. + gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs") + gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity") + let threshold = 0.9; + let toxic = false + + toxicity.load(threshold).then(model => { + model.classify(sentences).then(predictions => { + predictions.forEach(classified => { + if (classified.label == "toxicity") { + toxic = classified.results.match + } + }); + }); + }); + return toxic + } + async asyncSleep(ms) { await new Promise(r => setTimeout(r, ms)); } @@ -728,7 +749,8 @@ class JSPlusPlus { initGun(relays = []) { - JSPlusPlus.General.require("https://cdn.jsdelivr.net/npm/gun/gun.js") + let gen = new JSPlusPlus.General + gen.require("https://cdn.jsdelivr.net/npm/gun/gun.js") return Gun(relays) } }