AI-powered comment moderation plugin for PeerTube using two-stage German toxicity detection with ml6team DistilBERT and deepset BERT models.
- Dual-Model System:
- Primary:
ml6team/distilbert-base-german-cased-toxic-comments- Fast general toxicity detection (67M, optimized for comments) - Secondary:
deepset/bert-base-german-cased-hatespeech-GermEval18Coarse- Specialized hate speech detection
- Primary:
- German Language Detection: Automatically detects comment language using
langdetect - Two-Level Filtering:
- General toxicity threshold (configurable, default: 0.7)
- Hate speech threshold (configurable, default: 0.5)
- Non-German Comments: Configurable action for comments in other languages (moderation queue or block)
- Fail-Open Strategy: Comments are allowed if AI service is unavailable (prevents site breakage)
- Moderation Interface: Admin panel for reviewing and approving blocked comments
The plugin consists of two components:
- PeerTube Plugin (
peertube-plugin-aimod/) - PeerTube plugin that intercepts comments and sends them to AI service - AI Moderation Service (
ai-moderation/) - FastAPI service that runs ML models for toxicity detection
- PeerTube >= 7.0.0
- Docker and Docker Compose
- AI moderation service running in Docker network
- ~2GB disk space for ML models (cached in
/srv/ai-model-cache)
Install via PeerTube admin panel:
- Go to Administration → Plugins/Themes
- Click Install a plugin/the theme
- Enter package name:
peertube-plugin-german-ai-mod - Or upload ZIP file from releases
Or install via npm:
npm install peertube-plugin-german-ai-modAdd the AI moderation service to your docker-compose.yml:
services:
ai-moderator:
build: ./ai-moderation
container_name: ai-moderator
restart: unless-stopped
networks: [web]
environment:
- HF_HOME=/models
- TZ=Europe/Berlin
volumes:
- /srv/ai-model-cache:/models
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 5s
start_period: 40s
retries: 3Or use the provided docker-compose-ai-mod.yml file and merge it with your existing docker-compose configuration.
Important: Make sure the AI service is in the same Docker network as PeerTube (usually web network).
docker-compose up -d ai-moderatorThe first startup will download ML models (~2GB), which may take several minutes.
After installation, configure the plugin in PeerTube admin panel:
- AI Endpoint URL: URL of the AI moderation service (default:
http://ai-moderator:8000/analyze)- Must be accessible from PeerTube container
- Use Docker service name for internal network communication
- Toxizitäts-Schwelle (0–1): Threshold for general toxicity detection (default:
0.7) - Hate Speech Schwelle (0–1): Threshold for hate speech detection (default:
0.5) - Aktion für nicht-deutsche Kommentare:
Zur Moderation zurückhalten- Send to moderation queue (default)Blockieren- Block immediately
- Moderate (default): Toxicity 0.7, Hate Speech 0.5 - Blocks only explicit insults
- Strict: Toxicity 0.5, Hate Speech 0.4 - Blocks more aggressive comments
- Soft: Toxicity 0.8, Hate Speech 0.6 - Blocks only very explicit insults
Access the moderation interface at:
/admin/plugins/german-ai-mod/moderation
Features:
- View all blocked comments
- Filter by reason (toxic, non-German), status (pending, approved), or video
- Approve comments (unblock and publish)
- Delete comments permanently
- View toxicity scores and language detection results
- When a comment is created, the plugin sends it to the AI service
- AI service detects the language using
langdetect - For non-German comments: sends to moderation or blocks (based on settings)
- For German comments:
- Primary model checks general toxicity
- Secondary model checks for hate speech
- Comment is blocked if
score >= toxicity_thresholdORhate_score >= hate_threshold
- Toxic/hate speech comments are automatically blocked and saved to database
- Moderators can review and approve comments via admin interface
The plugin provides REST API endpoints for moderation:
GET /plugins/german-ai-mod/router/blocked-comments- List blocked commentsPOST /plugins/german-ai-mod/router/blocked-comments/:id/approve- Approve a commentDELETE /plugins/german-ai-mod/router/blocked-comments/:id- Delete a commentGET /plugins/german-ai-mod/router/my-videos- Get user's videos for filtering
The AI service provides a POST endpoint /analyze that accepts:
{
"text": "comment text here"
}And returns:
{
"toxic": false,
"score": 0.15,
"language": "de",
"is_german": true,
"requires_moderation": false,
"hate_score": 0.05
}Where:
toxic: boolean - whether comment should be blocked (based on thresholds)score: float (0-1) - general toxicity score from primary modelhate_score: float (0-1) - hate speech score from secondary modellanguage: string - detected language codeis_german: boolean - whether comment is in Germanrequires_moderation: boolean - whether comment requires manual review
filter:api.video-thread.create.accept.result- Main commentsfilter:api.video-comment-reply.create.accept.result- Repliesfilter:activity-pub.remote-video-comment.create.accept.result- Federated comments
-
Primary:
ml6team/distilbert-base-german-cased-toxic-comments- Lightweight (67M parameters)
- Trained on 5 German toxicity datasets
- Optimized for comment toxicity detection
-
Secondary:
deepset/bert-base-german-cased-hatespeech-GermEval18Coarse- Specialized for hate speech detection
- Trained on GermEval18 dataset
- Coarse-grained classification
- First request: ~5-10 seconds (model loading)
- Subsequent requests: ~200-500ms per comment
- Models are cached in
/srv/ai-model-cachevolume - Health check endpoint:
/health
- Check if container is running:
docker ps | grep ai-moderator - Check logs:
docker logs ai-moderator - Verify network connectivity:
docker exec peertube curl http://ai-moderator:8000/health - Check endpoint URL in plugin settings
- Check disk space:
df -h /srv/ai-model-cache - Check logs for download errors:
docker logs ai-moderator - Verify HuggingFace access (models are public, no token needed)
- Check plugin logs in PeerTube:
docker logs peertube | grep "AI Mod" - Verify thresholds in plugin settings
- Test AI service directly:
curl -X POST http://ai-moderator:8000/analyze -H "Content-Type: application/json" -d '{"text":"test comment"}'
cd ai-moderation
docker build -t ai-moderator .cd ai-moderation
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000cd peertube-plugin-aimod
npm installAGPL-3.0
yarkolife
https://github.com/yarkolife/peertube-plugin-german-ai-mod