Skip to content

raphcss/CloudyMod

Repository files navigation

CloudyMod - ML Toxicity Analysis Service

CloudyMod is the machine learning toxicity detection service for CloudyAI. It uses transformer-based models via Transformers.js to analyze text for toxic content across multiple languages.

🎯 Features

  • Multi-Model Support: Uses Xenova/toxic-bert for toxicity classification
  • Multi-Language: Automatic language detection via CloudyTrad
  • Slang Expansion: Expands common slang/abbreviations before analysis
  • Fast Inference: ONNX Runtime for optimized performance
  • API Authentication: Token-based security

🚀 Quick Start

Installation

cd CloudyMod
npm install

Configuration

Create .env file:

PORT=8001
API_TOKEN=your-secret-token-here
CLOUDYTRAD_URL=http://localhost:5001
CLOUDYTRAD_KEY=your-cloudytrad-token

Running

# Development
npm run dev

# Production
npm run build
npm start

📡 API Endpoints

POST /v1/ml/analyze

Analyze text for toxicity.

Headers:

Authorization: Bearer your-secret-token-here
Content-Type: application/json

Request:

{
  "text": "Your text to analyze",
  "lang": "auto"
}

Response:

{
  "scores": {
    "toxicity": 0.95,
    "severe_toxicity": 0.12,
    "obscene": 0.78,
    "threat": 0.05,
    "insult": 0.82,
    "identity_attack": 0.03,
    "sexual_explicit": 0.15
  },
  "language": "en"
}

GET /health

Health check endpoint (no authentication required).

Response:

{
  "status": "healthy",
  "service": "CloudyMod",
  "models": ["toxic-bert"]
}

🔧 Technical Details

Models

  • Xenova/toxic-bert: English toxicity classification
  • Uses ONNX Runtime for fast inference
  • Models are downloaded automatically on first run

Slang Expansion

CloudyMod expands common slang before analysis:

  • kyskill yourself
  • fdpfils de pute
  • ntmnique ta mère
  • And many more...

Language Detection

Integrates with CloudyTrad for automatic language detection to route text to the appropriate model.

📊 Performance

  • Inference Time: ~50-200ms per message
  • Memory Usage: ~500MB (with models loaded)
  • Concurrent Requests: Handles multiple simultaneous requests

🔒 Security

All endpoints except /health require authentication:

curl -X POST http://localhost:8001/v1/ml/analyze \
  -H "Authorization: Bearer your-secret-token-here" \
  -H "Content-Type: application/json" \
  -d '{"text":"test message","lang":"auto"}'

🐛 Troubleshooting

Models not downloading

  • Check internet connection
  • Ensure sufficient disk space (~500MB)
  • Check Hugging Face availability

High memory usage

  • Normal for transformer models
  • Consider increasing server RAM to 1GB+

Slow inference

  • First request is slower (model loading)
  • Subsequent requests are faster (~50-100ms)

📝 Environment Variables

Variable Description Default
PORT Server port 8001
API_TOKEN Authentication token your-secret-token-here
CLOUDYTRAD_URL CloudyTrad service URL http://localhost:5001
CLOUDYTRAD_KEY CloudyTrad API token ``

🔗 Integration

CloudyMod is called by CloudyAPI's moderation service:

const response = await fetch('http://localhost:8001/v1/ml/analyze', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your-token',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ text: message, lang: 'auto' })
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published