@joliegg/moderation 0.3.1 → 0.3.3

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/index.d.ts CHANGED
@@ -29,7 +29,7 @@ declare class ModerationClient {
29
29
  * Returns a list of moderation categories detected on an image
30
30
  *
31
31
  * @param {string} url
32
- * @param {number} [minimumConfidence = 95] The minimum confidence required for a category to be considered
32
+ * @param {number} [minimumConfidence = 50] The minimum confidence required for a category to be considered
33
33
  *
34
34
  *
35
35
  * @returns {Promise<ModerationResult[]>} The list of results that were detected with the minimum confidence specified
package/dist/index.js CHANGED
@@ -57,9 +57,10 @@ class ModerationClient {
57
57
  const normalizedText = text.toLowerCase();
58
58
  const matches = this.banList.filter(w => normalizedText.indexOf(w) > -1);
59
59
  if (matches.length > 0) {
60
+ const words = normalizedText.split(' ');
60
61
  categories.push({
61
62
  category: 'BAN_LIST',
62
- confidence: matches.length,
63
+ confidence: (matches.length / words.length) * 100,
63
64
  });
64
65
  }
65
66
  }
@@ -87,12 +88,12 @@ class ModerationClient {
87
88
  * Returns a list of moderation categories detected on an image
88
89
  *
89
90
  * @param {string} url
90
- * @param {number} [minimumConfidence = 95] The minimum confidence required for a category to be considered
91
+ * @param {number} [minimumConfidence = 50] The minimum confidence required for a category to be considered
91
92
  *
92
93
  *
93
94
  * @returns {Promise<ModerationResult[]>} The list of results that were detected with the minimum confidence specified
94
95
  */
95
- async moderateImage(url, minimumConfidence = 95) {
96
+ async moderateImage(url, minimumConfidence = 50) {
96
97
  if (typeof this.rekognitionClient === 'undefined') {
97
98
  return { source: url, moderation: [] };
98
99
  }
@@ -115,6 +116,7 @@ class ModerationClient {
115
116
  },
116
117
  MinConfidence: minimumConfidence
117
118
  });
119
+ console.log(ModerationLabels);
118
120
  if (Array.isArray(ModerationLabels)) {
119
121
  const moderation = ModerationLabels.map(l => ({
120
122
  category: l.Name ?? 'Unknown',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joliegg/moderation",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "A set of tools for chat moderation",
5
5
  "author": "Diana Islas Ocampo",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "test": "node test/index.js"
13
13
  },
14
14
  "engines": {
15
- "node": "20.x"
15
+ "node": ">=20.x"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@babel/eslint-parser": "^7.24.8",
package/src/index.ts CHANGED
@@ -73,9 +73,11 @@ class ModerationClient {
73
73
  const matches = this.banList.filter(w => normalizedText.indexOf(w) > -1);
74
74
 
75
75
  if (matches.length > 0) {
76
+ const words = normalizedText.split(' ');
77
+
76
78
  categories.push({
77
79
  category: 'BAN_LIST',
78
- confidence: matches.length,
80
+ confidence: (matches.length / words.length) * 100,
79
81
  });
80
82
  }
81
83
  }
@@ -109,12 +111,12 @@ class ModerationClient {
109
111
  * Returns a list of moderation categories detected on an image
110
112
  *
111
113
  * @param {string} url
112
- * @param {number} [minimumConfidence = 95] The minimum confidence required for a category to be considered
114
+ * @param {number} [minimumConfidence = 50] The minimum confidence required for a category to be considered
113
115
  *
114
116
  *
115
117
  * @returns {Promise<ModerationResult[]>} The list of results that were detected with the minimum confidence specified
116
118
  */
117
- async moderateImage (url: string, minimumConfidence: number = 95): Promise<ModerationResult> {
119
+ async moderateImage (url: string, minimumConfidence: number = 50): Promise<ModerationResult> {
118
120
  if (typeof this.rekognitionClient === 'undefined') {
119
121
  return { source: url, moderation: [] };
120
122
  }
@@ -140,6 +142,8 @@ class ModerationClient {
140
142
  MinConfidence: minimumConfidence
141
143
  });
142
144
 
145
+ console.log(ModerationLabels);
146
+
143
147
  if (Array.isArray(ModerationLabels)) {
144
148
  const moderation = ModerationLabels.map(l => ({
145
149
  category: l.Name ?? 'Unknown',