glin-profanity 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{types-Dj5vaoch.d.cts → Filter-BGcyIAvO.d.ts} +2 -162
- package/dist/{types-Dj5vaoch.d.ts → Filter-D34Wsmrj.d.cts} +2 -162
- package/dist/frameworks/index.cjs +5257 -0
- package/dist/frameworks/index.d.cts +2 -0
- package/dist/frameworks/index.d.ts +2 -0
- package/dist/frameworks/index.js +5252 -0
- package/dist/frameworks/nextjs.cjs +5257 -0
- package/dist/frameworks/nextjs.d.cts +173 -0
- package/dist/frameworks/nextjs.d.ts +173 -0
- package/dist/frameworks/nextjs.js +5252 -0
- package/dist/index.cjs +0 -28
- package/dist/index.d.cts +5 -29
- package/dist/index.d.ts +5 -29
- package/dist/index.js +1 -28
- package/dist/integrations/index.cjs +6110 -0
- package/dist/integrations/index.d.cts +5 -0
- package/dist/integrations/index.d.ts +5 -0
- package/dist/integrations/index.js +6082 -0
- package/dist/integrations/langchain.cjs +5252 -0
- package/dist/integrations/langchain.d.cts +231 -0
- package/dist/integrations/langchain.d.ts +231 -0
- package/dist/integrations/langchain.js +5239 -0
- package/dist/integrations/openai.cjs +5367 -0
- package/dist/integrations/openai.d.cts +167 -0
- package/dist/integrations/openai.d.ts +167 -0
- package/dist/integrations/openai.js +5362 -0
- package/dist/integrations/semantic.cjs +5314 -0
- package/dist/integrations/semantic.d.cts +268 -0
- package/dist/integrations/semantic.d.ts +268 -0
- package/dist/integrations/semantic.js +5309 -0
- package/dist/integrations/vercel-ai.cjs +5282 -0
- package/dist/integrations/vercel-ai.d.cts +224 -0
- package/dist/integrations/vercel-ai.d.ts +224 -0
- package/dist/integrations/vercel-ai.js +5273 -0
- package/dist/ml/index.cjs +207 -0
- package/dist/ml/index.d.cts +5 -2
- package/dist/ml/index.d.ts +5 -2
- package/dist/ml/index.js +203 -1
- package/dist/ml/transformers.cjs +5237 -0
- package/dist/ml/transformers.d.cts +232 -0
- package/dist/ml/transformers.d.ts +232 -0
- package/dist/ml/transformers.js +5231 -0
- package/dist/multimodal/audio.cjs +5269 -0
- package/dist/multimodal/audio.d.cts +255 -0
- package/dist/multimodal/audio.d.ts +255 -0
- package/dist/multimodal/audio.js +5264 -0
- package/dist/multimodal/index.cjs +5432 -0
- package/dist/multimodal/index.d.cts +4 -0
- package/dist/multimodal/index.d.ts +4 -0
- package/dist/multimodal/index.js +5422 -0
- package/dist/multimodal/ocr.cjs +5193 -0
- package/dist/multimodal/ocr.d.cts +157 -0
- package/dist/multimodal/ocr.d.ts +157 -0
- package/dist/multimodal/ocr.js +5187 -0
- package/dist/react.cjs +5133 -0
- package/dist/react.d.cts +13 -0
- package/dist/react.d.ts +13 -0
- package/dist/react.js +5131 -0
- package/dist/types-B9c_ik4k.d.cts +88 -0
- package/dist/types-B9c_ik4k.d.ts +88 -0
- package/dist/types-BuKh9tvV.d.ts +20 -0
- package/dist/types-Ct_ueYqw.d.cts +76 -0
- package/dist/types-Ct_ueYqw.d.ts +76 -0
- package/dist/types-DI8nzwWc.d.cts +20 -0
- package/package.json +170 -3
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { F as Filter } from '../Filter-D34Wsmrj.cjs';
|
|
2
|
+
import { F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.cjs';
|
|
3
|
+
export { L as Language } from '../types-B9c_ik4k.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transformers.js ML Integration for glin-profanity
|
|
7
|
+
*
|
|
8
|
+
* Provides ML-based profanity detection using Hugging Face models
|
|
9
|
+
* via transformers.js. This is an optional enhancement that adds
|
|
10
|
+
* context-aware detection on top of the dictionary-based approach.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createMLChecker, createHybridChecker } from 'glin-profanity/ml/transformers';
|
|
15
|
+
*
|
|
16
|
+
* // ML-only checker
|
|
17
|
+
* const mlChecker = await createMLChecker({
|
|
18
|
+
* model: 'tarekziade/pardonmyai',
|
|
19
|
+
* });
|
|
20
|
+
* const result = await mlChecker.check('Some text to check');
|
|
21
|
+
*
|
|
22
|
+
* // Hybrid: Dictionary + ML (recommended)
|
|
23
|
+
* const hybridChecker = await createHybridChecker({
|
|
24
|
+
* model: 'tarekziade/pardonmyai',
|
|
25
|
+
* mlThreshold: 0.7, // Only use ML if dictionary is uncertain
|
|
26
|
+
* });
|
|
27
|
+
* const result = await hybridChecker.check('Some text to check');
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @packageDocumentation
|
|
31
|
+
* @module glin-profanity/ml/transformers
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ML checker configuration
|
|
36
|
+
*/
|
|
37
|
+
interface MLCheckerConfig {
|
|
38
|
+
/** Hugging Face model ID */
|
|
39
|
+
model?: string;
|
|
40
|
+
/** Confidence threshold (0-1) for flagging as profane */
|
|
41
|
+
threshold?: number;
|
|
42
|
+
/** Label that indicates profanity (model-specific) */
|
|
43
|
+
profaneLabel?: string;
|
|
44
|
+
/** Use quantized model for smaller size */
|
|
45
|
+
quantized?: boolean;
|
|
46
|
+
/** Device to run on ('cpu', 'webgpu', etc.) */
|
|
47
|
+
device?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hybrid checker configuration
|
|
51
|
+
*/
|
|
52
|
+
interface HybridCheckerConfig extends MLCheckerConfig {
|
|
53
|
+
/** Filter configuration for dictionary-based checking */
|
|
54
|
+
filterConfig?: Partial<FilterConfig>;
|
|
55
|
+
/** ML confidence threshold below which to use ML */
|
|
56
|
+
mlThreshold?: number;
|
|
57
|
+
/** Weight for dictionary score (0-1) */
|
|
58
|
+
dictionaryWeight?: number;
|
|
59
|
+
/** Weight for ML score (0-1) */
|
|
60
|
+
mlWeight?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* ML check result
|
|
64
|
+
*/
|
|
65
|
+
interface MLCheckResult {
|
|
66
|
+
/** Whether profanity was detected */
|
|
67
|
+
containsProfanity: boolean;
|
|
68
|
+
/** Confidence score (0-1) */
|
|
69
|
+
confidence: number;
|
|
70
|
+
/** Raw model output */
|
|
71
|
+
rawOutput: Array<{
|
|
72
|
+
label: string;
|
|
73
|
+
score: number;
|
|
74
|
+
}>;
|
|
75
|
+
/** Processing time in milliseconds */
|
|
76
|
+
processingTimeMs: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Hybrid check result
|
|
80
|
+
*/
|
|
81
|
+
interface HybridCheckResult {
|
|
82
|
+
/** Whether profanity was detected */
|
|
83
|
+
containsProfanity: boolean;
|
|
84
|
+
/** Combined confidence score (0-1) */
|
|
85
|
+
confidence: number;
|
|
86
|
+
/** Dictionary check result */
|
|
87
|
+
dictionaryResult: CheckProfanityResult;
|
|
88
|
+
/** ML check result (if used) */
|
|
89
|
+
mlResult?: MLCheckResult;
|
|
90
|
+
/** Whether ML was used */
|
|
91
|
+
usedML: boolean;
|
|
92
|
+
/** Profane words found (from dictionary) */
|
|
93
|
+
profaneWords: string[];
|
|
94
|
+
/** Processing time in milliseconds */
|
|
95
|
+
processingTimeMs: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Popular profanity detection models on Hugging Face
|
|
99
|
+
*/
|
|
100
|
+
declare const RECOMMENDED_MODELS: {
|
|
101
|
+
/** High accuracy English model (97.5%) - 67M params */
|
|
102
|
+
readonly pardonmyai: "tarekziade/pardonmyai";
|
|
103
|
+
/** Smaller version for constrained environments */
|
|
104
|
+
readonly pardonmyaiTiny: "tarekziade/pardonmyai-tiny";
|
|
105
|
+
/** Multilingual toxicity detection (7 languages) */
|
|
106
|
+
readonly toxicBert: "unitary/toxic-bert";
|
|
107
|
+
/** Offensive speech detector (DeBERTa-based) */
|
|
108
|
+
readonly offensiveSpeech: "KoalaAI/OffensiveSpeechDetector";
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Creates an ML-based profanity checker using transformers.js
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const checker = await createMLChecker({
|
|
116
|
+
* model: 'tarekziade/pardonmyai',
|
|
117
|
+
* threshold: 0.7,
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* const result = await checker.check('Hello world');
|
|
121
|
+
* console.log(result.containsProfanity); // false
|
|
122
|
+
* console.log(result.confidence); // 0.02
|
|
123
|
+
*
|
|
124
|
+
* // Batch check
|
|
125
|
+
* const results = await checker.checkBatch(['text1', 'text2', 'text3']);
|
|
126
|
+
*
|
|
127
|
+
* // Clean up
|
|
128
|
+
* checker.dispose();
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function createMLChecker(config?: MLCheckerConfig): Promise<{
|
|
132
|
+
/**
|
|
133
|
+
* Check a single text for profanity
|
|
134
|
+
*/
|
|
135
|
+
check(text: string): Promise<MLCheckResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Check multiple texts
|
|
138
|
+
*/
|
|
139
|
+
checkBatch(texts: string[]): Promise<MLCheckResult[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Get the profanity score for text (0-1)
|
|
142
|
+
*/
|
|
143
|
+
getScore(text: string): Promise<number>;
|
|
144
|
+
/**
|
|
145
|
+
* Get current configuration
|
|
146
|
+
*/
|
|
147
|
+
getConfig(): {
|
|
148
|
+
model: string;
|
|
149
|
+
threshold: number;
|
|
150
|
+
profaneLabel: string;
|
|
151
|
+
quantized: boolean;
|
|
152
|
+
device: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Dispose of the model (free memory)
|
|
156
|
+
*/
|
|
157
|
+
dispose(): void;
|
|
158
|
+
}>;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a hybrid checker that combines dictionary + ML
|
|
161
|
+
*
|
|
162
|
+
* Strategy:
|
|
163
|
+
* 1. Dictionary check first (fast, ~1ms)
|
|
164
|
+
* 2. If dictionary finds profanity → flag immediately
|
|
165
|
+
* 3. If dictionary is clean but text is suspicious → use ML
|
|
166
|
+
* 4. Combine scores with configurable weights
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const checker = await createHybridChecker({
|
|
171
|
+
* model: 'tarekziade/pardonmyai',
|
|
172
|
+
* filterConfig: { languages: ['english'], detectLeetspeak: true },
|
|
173
|
+
* mlThreshold: 0.6,
|
|
174
|
+
* dictionaryWeight: 0.6,
|
|
175
|
+
* mlWeight: 0.4,
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* const result = await checker.check('Hello world');
|
|
179
|
+
* console.log(result.containsProfanity);
|
|
180
|
+
* console.log(result.usedML); // true if ML was invoked
|
|
181
|
+
*
|
|
182
|
+
* // Clean up
|
|
183
|
+
* await checker.dispose();
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function createHybridChecker(config?: HybridCheckerConfig): Promise<{
|
|
187
|
+
/**
|
|
188
|
+
* Check text using hybrid approach
|
|
189
|
+
*/
|
|
190
|
+
check(text: string): Promise<HybridCheckResult>;
|
|
191
|
+
/**
|
|
192
|
+
* Check multiple texts
|
|
193
|
+
*/
|
|
194
|
+
checkBatch(texts: string[]): Promise<HybridCheckResult[]>;
|
|
195
|
+
/**
|
|
196
|
+
* Dictionary-only check (fast, no ML)
|
|
197
|
+
*/
|
|
198
|
+
checkFast(text: string): CheckProfanityResult;
|
|
199
|
+
/**
|
|
200
|
+
* ML-only check (slower, more accurate)
|
|
201
|
+
*/
|
|
202
|
+
checkML(text: string): Promise<MLCheckResult>;
|
|
203
|
+
/**
|
|
204
|
+
* Get the underlying filter
|
|
205
|
+
*/
|
|
206
|
+
getFilter(): Filter;
|
|
207
|
+
/**
|
|
208
|
+
* Dispose of resources
|
|
209
|
+
*/
|
|
210
|
+
dispose(): Promise<void>;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Check if transformers.js is available
|
|
214
|
+
*/
|
|
215
|
+
declare function isTransformersAvailable(): Promise<boolean>;
|
|
216
|
+
/**
|
|
217
|
+
* Pre-download a model for faster first inference
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* // Pre-load during app initialization
|
|
222
|
+
* await preloadModel('tarekziade/pardonmyai');
|
|
223
|
+
*
|
|
224
|
+
* // Later, checker will start faster
|
|
225
|
+
* const checker = await createMLChecker({ model: 'tarekziade/pardonmyai' });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function preloadModel(model?: string, options?: {
|
|
229
|
+
quantized?: boolean;
|
|
230
|
+
}): Promise<void>;
|
|
231
|
+
|
|
232
|
+
export { CheckProfanityResult, FilterConfig, type HybridCheckResult, type HybridCheckerConfig, type MLCheckResult, type MLCheckerConfig, RECOMMENDED_MODELS, createHybridChecker, createMLChecker, isTransformersAvailable, preloadModel };
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { F as Filter } from '../Filter-BGcyIAvO.js';
|
|
2
|
+
import { F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.js';
|
|
3
|
+
export { L as Language } from '../types-B9c_ik4k.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transformers.js ML Integration for glin-profanity
|
|
7
|
+
*
|
|
8
|
+
* Provides ML-based profanity detection using Hugging Face models
|
|
9
|
+
* via transformers.js. This is an optional enhancement that adds
|
|
10
|
+
* context-aware detection on top of the dictionary-based approach.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createMLChecker, createHybridChecker } from 'glin-profanity/ml/transformers';
|
|
15
|
+
*
|
|
16
|
+
* // ML-only checker
|
|
17
|
+
* const mlChecker = await createMLChecker({
|
|
18
|
+
* model: 'tarekziade/pardonmyai',
|
|
19
|
+
* });
|
|
20
|
+
* const result = await mlChecker.check('Some text to check');
|
|
21
|
+
*
|
|
22
|
+
* // Hybrid: Dictionary + ML (recommended)
|
|
23
|
+
* const hybridChecker = await createHybridChecker({
|
|
24
|
+
* model: 'tarekziade/pardonmyai',
|
|
25
|
+
* mlThreshold: 0.7, // Only use ML if dictionary is uncertain
|
|
26
|
+
* });
|
|
27
|
+
* const result = await hybridChecker.check('Some text to check');
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @packageDocumentation
|
|
31
|
+
* @module glin-profanity/ml/transformers
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ML checker configuration
|
|
36
|
+
*/
|
|
37
|
+
interface MLCheckerConfig {
|
|
38
|
+
/** Hugging Face model ID */
|
|
39
|
+
model?: string;
|
|
40
|
+
/** Confidence threshold (0-1) for flagging as profane */
|
|
41
|
+
threshold?: number;
|
|
42
|
+
/** Label that indicates profanity (model-specific) */
|
|
43
|
+
profaneLabel?: string;
|
|
44
|
+
/** Use quantized model for smaller size */
|
|
45
|
+
quantized?: boolean;
|
|
46
|
+
/** Device to run on ('cpu', 'webgpu', etc.) */
|
|
47
|
+
device?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hybrid checker configuration
|
|
51
|
+
*/
|
|
52
|
+
interface HybridCheckerConfig extends MLCheckerConfig {
|
|
53
|
+
/** Filter configuration for dictionary-based checking */
|
|
54
|
+
filterConfig?: Partial<FilterConfig>;
|
|
55
|
+
/** ML confidence threshold below which to use ML */
|
|
56
|
+
mlThreshold?: number;
|
|
57
|
+
/** Weight for dictionary score (0-1) */
|
|
58
|
+
dictionaryWeight?: number;
|
|
59
|
+
/** Weight for ML score (0-1) */
|
|
60
|
+
mlWeight?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* ML check result
|
|
64
|
+
*/
|
|
65
|
+
interface MLCheckResult {
|
|
66
|
+
/** Whether profanity was detected */
|
|
67
|
+
containsProfanity: boolean;
|
|
68
|
+
/** Confidence score (0-1) */
|
|
69
|
+
confidence: number;
|
|
70
|
+
/** Raw model output */
|
|
71
|
+
rawOutput: Array<{
|
|
72
|
+
label: string;
|
|
73
|
+
score: number;
|
|
74
|
+
}>;
|
|
75
|
+
/** Processing time in milliseconds */
|
|
76
|
+
processingTimeMs: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Hybrid check result
|
|
80
|
+
*/
|
|
81
|
+
interface HybridCheckResult {
|
|
82
|
+
/** Whether profanity was detected */
|
|
83
|
+
containsProfanity: boolean;
|
|
84
|
+
/** Combined confidence score (0-1) */
|
|
85
|
+
confidence: number;
|
|
86
|
+
/** Dictionary check result */
|
|
87
|
+
dictionaryResult: CheckProfanityResult;
|
|
88
|
+
/** ML check result (if used) */
|
|
89
|
+
mlResult?: MLCheckResult;
|
|
90
|
+
/** Whether ML was used */
|
|
91
|
+
usedML: boolean;
|
|
92
|
+
/** Profane words found (from dictionary) */
|
|
93
|
+
profaneWords: string[];
|
|
94
|
+
/** Processing time in milliseconds */
|
|
95
|
+
processingTimeMs: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Popular profanity detection models on Hugging Face
|
|
99
|
+
*/
|
|
100
|
+
declare const RECOMMENDED_MODELS: {
|
|
101
|
+
/** High accuracy English model (97.5%) - 67M params */
|
|
102
|
+
readonly pardonmyai: "tarekziade/pardonmyai";
|
|
103
|
+
/** Smaller version for constrained environments */
|
|
104
|
+
readonly pardonmyaiTiny: "tarekziade/pardonmyai-tiny";
|
|
105
|
+
/** Multilingual toxicity detection (7 languages) */
|
|
106
|
+
readonly toxicBert: "unitary/toxic-bert";
|
|
107
|
+
/** Offensive speech detector (DeBERTa-based) */
|
|
108
|
+
readonly offensiveSpeech: "KoalaAI/OffensiveSpeechDetector";
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Creates an ML-based profanity checker using transformers.js
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const checker = await createMLChecker({
|
|
116
|
+
* model: 'tarekziade/pardonmyai',
|
|
117
|
+
* threshold: 0.7,
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* const result = await checker.check('Hello world');
|
|
121
|
+
* console.log(result.containsProfanity); // false
|
|
122
|
+
* console.log(result.confidence); // 0.02
|
|
123
|
+
*
|
|
124
|
+
* // Batch check
|
|
125
|
+
* const results = await checker.checkBatch(['text1', 'text2', 'text3']);
|
|
126
|
+
*
|
|
127
|
+
* // Clean up
|
|
128
|
+
* checker.dispose();
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function createMLChecker(config?: MLCheckerConfig): Promise<{
|
|
132
|
+
/**
|
|
133
|
+
* Check a single text for profanity
|
|
134
|
+
*/
|
|
135
|
+
check(text: string): Promise<MLCheckResult>;
|
|
136
|
+
/**
|
|
137
|
+
* Check multiple texts
|
|
138
|
+
*/
|
|
139
|
+
checkBatch(texts: string[]): Promise<MLCheckResult[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Get the profanity score for text (0-1)
|
|
142
|
+
*/
|
|
143
|
+
getScore(text: string): Promise<number>;
|
|
144
|
+
/**
|
|
145
|
+
* Get current configuration
|
|
146
|
+
*/
|
|
147
|
+
getConfig(): {
|
|
148
|
+
model: string;
|
|
149
|
+
threshold: number;
|
|
150
|
+
profaneLabel: string;
|
|
151
|
+
quantized: boolean;
|
|
152
|
+
device: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Dispose of the model (free memory)
|
|
156
|
+
*/
|
|
157
|
+
dispose(): void;
|
|
158
|
+
}>;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a hybrid checker that combines dictionary + ML
|
|
161
|
+
*
|
|
162
|
+
* Strategy:
|
|
163
|
+
* 1. Dictionary check first (fast, ~1ms)
|
|
164
|
+
* 2. If dictionary finds profanity → flag immediately
|
|
165
|
+
* 3. If dictionary is clean but text is suspicious → use ML
|
|
166
|
+
* 4. Combine scores with configurable weights
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const checker = await createHybridChecker({
|
|
171
|
+
* model: 'tarekziade/pardonmyai',
|
|
172
|
+
* filterConfig: { languages: ['english'], detectLeetspeak: true },
|
|
173
|
+
* mlThreshold: 0.6,
|
|
174
|
+
* dictionaryWeight: 0.6,
|
|
175
|
+
* mlWeight: 0.4,
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* const result = await checker.check('Hello world');
|
|
179
|
+
* console.log(result.containsProfanity);
|
|
180
|
+
* console.log(result.usedML); // true if ML was invoked
|
|
181
|
+
*
|
|
182
|
+
* // Clean up
|
|
183
|
+
* await checker.dispose();
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function createHybridChecker(config?: HybridCheckerConfig): Promise<{
|
|
187
|
+
/**
|
|
188
|
+
* Check text using hybrid approach
|
|
189
|
+
*/
|
|
190
|
+
check(text: string): Promise<HybridCheckResult>;
|
|
191
|
+
/**
|
|
192
|
+
* Check multiple texts
|
|
193
|
+
*/
|
|
194
|
+
checkBatch(texts: string[]): Promise<HybridCheckResult[]>;
|
|
195
|
+
/**
|
|
196
|
+
* Dictionary-only check (fast, no ML)
|
|
197
|
+
*/
|
|
198
|
+
checkFast(text: string): CheckProfanityResult;
|
|
199
|
+
/**
|
|
200
|
+
* ML-only check (slower, more accurate)
|
|
201
|
+
*/
|
|
202
|
+
checkML(text: string): Promise<MLCheckResult>;
|
|
203
|
+
/**
|
|
204
|
+
* Get the underlying filter
|
|
205
|
+
*/
|
|
206
|
+
getFilter(): Filter;
|
|
207
|
+
/**
|
|
208
|
+
* Dispose of resources
|
|
209
|
+
*/
|
|
210
|
+
dispose(): Promise<void>;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Check if transformers.js is available
|
|
214
|
+
*/
|
|
215
|
+
declare function isTransformersAvailable(): Promise<boolean>;
|
|
216
|
+
/**
|
|
217
|
+
* Pre-download a model for faster first inference
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* // Pre-load during app initialization
|
|
222
|
+
* await preloadModel('tarekziade/pardonmyai');
|
|
223
|
+
*
|
|
224
|
+
* // Later, checker will start faster
|
|
225
|
+
* const checker = await createMLChecker({ model: 'tarekziade/pardonmyai' });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
declare function preloadModel(model?: string, options?: {
|
|
229
|
+
quantized?: boolean;
|
|
230
|
+
}): Promise<void>;
|
|
231
|
+
|
|
232
|
+
export { CheckProfanityResult, FilterConfig, type HybridCheckResult, type HybridCheckerConfig, type MLCheckResult, type MLCheckerConfig, RECOMMENDED_MODELS, createHybridChecker, createMLChecker, isTransformersAvailable, preloadModel };
|