File size: 8,646 Bytes
1c3fe08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# Feedback Moderation API - Test Data

Test data for the Wasla Feedback Moderation API.

## Configuration

```bash
API_URL="http://127.0.0.1:8000/api/v1/moderate"
API_KEY="your-api-key-here"
```

---

## Health Check

```bash
curl http://127.0.0.1:8000/health
```

**Expected Response:**
```json
{
  "status": "ok",
  "multilingual_model_loaded": true,
  "arabic_model_loaded": true,
  "llm_verification_enabled": false
}
```

---

## English Test Cases

### Toxic Examples

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "You are an idiot and your family should leave"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "This product is terrible and I hate everything about it!"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "You are stupid and worthless"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Shut up you moron, nobody cares about your opinion"}'
```

### Clean Examples

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Thank you for the wonderful service"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "I absolutely love this product!"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "The delivery was fast and the quality exceeded my expectations."}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Great customer support, very helpful team."}'
```

---

## Arabic Test Cases

### Toxic Examples (Arabic)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "أنت حيوان قذر و غبي يجب أن تموت"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "اخرس يا حقير، لا أحد يهتم برأيك"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "أنت غبي جداً ولا تستحق العيش"}'
```

### Clean Examples (Arabic)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "شكراً لكم على الخدمة الممتازة"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "أعجبني المنتج كثيراً، الجودة ممتازة"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "التوصيل كان سريعاً والخدمة رائعة"}'
```

---

## French Test Cases

### Toxic Examples (French)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Tu es un sale idiot, je vais te tuer espèce de merde"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Ferme-la, espèce de débile mental"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Tu ne vaux rien, dégage!"}'
```

### Clean Examples (French)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Merci beaucoup pour votre aide"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Service excellent, je recommande!"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "La livraison était rapide et le produit conforme à la description."}'
```

---

## Italian Test Cases

### Toxic Examples (Italian)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Sei uno stupido e non vali niente"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Stai zitto, idiota! Nessuno ti vuole qui"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Sei un fallito totale, vattene via"}'
```

### Clean Examples (Italian)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Grazie mille per il vostro ottimo servizio"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Prodotto eccellente, consegna veloce!"}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Sono molto soddisfatto del servizio clienti."}'
```

---

## Edge Cases

### Short Text

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "ok"}'
```

### Mixed Language

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello, شكراً for your help"}'
```

### Numbers and Special Characters

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Order #12345 received. Rating: 5/5 stars!"}'
```

### Negative but Non-Toxic Feedback

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "I am disappointed with the late delivery. Please improve."}'
```

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "The product did not meet my expectations. I would like a refund."}'
```

---

## Error Cases

### Missing API Key

```bash
curl -X POST "$API_URL" \
  -H "Content-Type: application/json" \
  -d '{"text": "test"}'
```

**Expected Response:** `403 Forbidden`

### Invalid API Key

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: wrong-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "test"}'
```

**Expected Response:** `403 Forbidden`

### Empty Text

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": ""}'
```

**Expected Response:** `422 Unprocessable Entity`

### Text Too Long (>5000 chars)

```bash
curl -X POST "$API_URL" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"text\": \"$(python -c 'print("x" * 5001)')\"}"
```

**Expected Response:** `422 Unprocessable Entity`

---

## Python Test Script

```python
import requests

API_URL = "http://127.0.0.1:8000/api/v1/moderate"
API_KEY = "your-api-key-here"

test_cases = [
    ("en", True, "You are an idiot and your family should leave"),
    ("en", False, "Thank you for the wonderful service"),
    ("ar", True, "أنت حيوان قذر و غبي يجب أن تموت"),
    ("ar", False, "شكراً لكم على الخدمة الممتازة"),
    ("fr", True, "Tu es un sale idiot, je vais te tuer espèce de merde"),
    ("fr", False, "Merci beaucoup pour votre aide"),
    ("it", True, "Sei uno stupido e non vali niente"),
    ("it", False, "Grazie mille per il vostro ottimo servizio"),
]

headers = {"X-API-Key": API_KEY}

for lang, expected_toxic, text in test_cases:
    r = requests.post(API_URL, json={"text": text}, headers=headers)
    data = r.json()
    flag = "FAIL" if data["has_bad_words"] != expected_toxic else "PASS"
    print(f"[{flag}] {lang.upper()} - Expected toxic={expected_toxic}, Got: {data}")
```

---

## Expected Response Format

```json
{
  "has_bad_words": true,
  "confidence": 0.9812,
  "label": "toxic",
  "detected_language": "en",
  "llm_verified": false
}
```

| Field | Type | Description |
|-------|------|-------------|
| `has_bad_words` | boolean | True if text is toxic (above threshold) |
| `confidence` | float | Toxicity probability (0.0 - 1.0) |
| `label` | string | Raw model label (`toxic`/`not_toxic` or `HATE`/`NON_HATE`) |
| `detected_language` | string | ISO 639-1 code (`en`, `ar`, `fr`, `it`, `unknown`) |
| `llm_verified` | boolean | True if LLM verification was used |