feat: add content moderation module#745
Open
Deywumi-debug wants to merge 1 commit into
Open
Conversation
- OpenAI moderation API integration (POST /moderation/check) - Local profanity filtering with stem-matching regex patterns - Spam detection (repeated chars, URL flooding, spam phrases, excessive caps) - Auto-reject on any violation with flags and human-readable reason - ModerationService exported for use by other modules - 14 unit tests, all passing - Gated behind ENABLE_MODERATION feature flag
Contributor
|
Kindly resolve conflict and fix workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
ModerationModulethat scans submitted content for inappropriate material before it reaches the platform. All checks run on everyPOST /moderation/checkrequest and any violation auto-rejects the content.Changes
src/modules/moderation/moderation.service.tssrc/modules/moderation/moderation.controller.tsPOST /moderation/checkendpointsrc/modules/moderation/moderation.module.tsHttpModulesrc/modules/moderation/dto/moderate-content.dto.tssrc/modules/moderation/dto/moderation-result.dto.tssrc/modules/moderation/moderation.service.spec.tssrc/app.module.tsENABLE_MODERATIONflagAcceptance Criteria
POST https://api.openai.com/v1/moderationsviaHttpService; requiresOPENAI_API_KEYenv var; skipped gracefully if absent or on network failureallowed: false,autoRejected: true, and a human-readablereasonAPI
Response:
{ "allowed": false, "autoRejected": true, "flags": ["spam", "profanity"], "reason": "detected as spam; contains profanity" }Configuration
Testing
14 unit tests covering: clean content pass-through, profanity (case-insensitive), spam signals (repeated chars, URL flooding, spam phrases, excessive caps), OpenAI flagged/not-flagged/error/no-key, auto-reject with reason, and multiple flag accumulation.
npm test -- src/modules/moderation/moderation.service.spec.ts --no-coverageNotes
ModerationServiceis exported from the module so other modules (courses, posts, etc.) can inject it to gate content submission at the service layer.ENABLE_MODERATION) and can be disabled without touching application code.closes Add automated content safety scanning #560