From cd679dba4ec7235f791b7bb1cd90b8d232a23afc Mon Sep 17 00:00:00 2001 From: Sam Sneed <163201376+sam-sneed@users.noreply.github.com> Date: Fri, 31 May 2024 20:31:27 +0000 Subject: [PATCH] Update jspp.js --- jspp.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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) } }