Spaces:
Running
Running
File size: 857 Bytes
ae601ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | const BLOCK_PATTERNS: Array<{ label: string; pattern: RegExp }> = [
{ label: "hate slur", pattern: /\b(?:nigger|faggot|kike|chink)\b/i },
{ label: "sexual slur", pattern: /\b(?:cunt|whore)\b/i },
{ label: "explicit profanity", pattern: /\b(?:fuck|motherfucker|shit|asshole|bitch)\b/i },
{ label: "violent abuse", pattern: /\b(?:rape|kill\s+all|exterminate\s+all)\b/i },
];
export function findBlockedContent(...inputs: Array<string | undefined | null>) {
const text = inputs
.filter((value): value is string => typeof value === "string" && value.trim().length > 0)
.join("\n")
.slice(0, 5000);
if (!text) {
return { blocked: false, labels: [] as string[] };
}
const labels = BLOCK_PATTERNS.filter((item) => item.pattern.test(text)).map((item) => item.label);
return {
blocked: labels.length > 0,
labels,
};
}
|