Merge LibSi(e)ve with JS++

This commit is contained in:
The Ghost of FOSS' Past 2024-12-06 20:22:40 -06:00
parent 6da0f0e6b6
commit 8b18d5d8bd

32
jspp.js
View file

@ -14,16 +14,40 @@ class JSPlusPlus {
async isToxic(sentences) { async isToxic(sentences) {
// Load the model. Users optionally pass in a threshold and an array of // Load the model. Users optionally pass in a threshold and an array of
// labels to include. // labels to include.
const gen = new JSPlusPlus.General const gen = new JSPlusPlus.General
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs") gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs")
gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity") gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity")
let threshold = 0.9; let threshold = 0.9;
let t = await toxicity.load(threshold).then(model => { let t = await toxicity.load(threshold).then(model => {
return model.classify(sentences).then(predictions => { return model.classify(sentences).then(predictions => {
return predictions return predictions
}); });
}); });
return t return t
}
isPrime = num => {
for(let i = 2, s = Math.sqrt(num); i <= s; i++) {
if(num % i === 0) return false;
}
return num > 1;
}
sieve(siveTo) {
let primes = []
siveTo = Number(siveTo)
for (var i = 1; i < siveTo; i++) {
if (isPrime(i)) {
primes.push(i)
}
}
if (isPrime(siveTo)) {
primes.push(siveTo)
}
return primes
} }
async asyncSleep(ms) { async asyncSleep(ms) {