The goal of this project is to develop a streamlined API for managing posts and comments with integrated AI moderation and automated response functionality. Built using the Django Ninja framework, the system leverages GeminiAI for intelligent content moderation and Celery for automated response task handling, ensuring efficient processing of moderation tasks and automated replies.
To use the API, you need to create a user account and obtain a JWT token:
- Register:
POST /api/user/register
- Obtain token:
POST /api/user/token/pair
- Verify token:
POST /api/user/token/verify
- Refresh token:
POST /api/user/token/refresh
-
User registration and JWT authentication
- Self-registration with username and password.
- Login using JWT for secure access.
-
Post management API
- Create, retrieve, update, and delete posts.
- Each post is subject to AI-driven moderation to detect offensive language or inappropriate content before it is published.
-
Comment management API
- Create, retrieve, update, and delete comments on posts.
- Comments are also checked for offensive language, with options to block inappropriate comments.
-
AI moderation:
- Using GeminiAI automatically scans posts and comments for profanity, offensive language, or hate speech
- Content failing the moderation check is flagged or blocked.
-
Analytics on comments
- Provides a daily breakdown of comments over a specified period.
- Example URL:
/api/comments/daily-breakdown?date_from=2024-10-23&date_to=2024-10-26
. - Returns aggregated statistics by day, showing the number of comments created and the number of blocked comments.
-
Automated comment responses
- Users can enable automated responses to comments on their posts.
- Responses are generated based on the content of the post and the comment, with a configurable delay set by the user.
-
Access control
- Users can edit / delete only their own post and comments
- Post author can delete comments related to his posts
- Admins can delete all posts and comments
- Framework: Django Ninja
- AI Moderation: GeminiAI for free AI-based content moderation.
- Background task processing: Celery to handle delayed responses.
Note: The Gemini API and Google AI Studio may not be avaliablee in your region, and the AI Moderation feature will not work! Consider using vpn. List of available countries or territories
- Clone the repository:
git clone https://github.com/lilarin/AI-Moderation-Blog-API.git
- Create a virtual environment:
python -m venv env source env/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Apply migrations:
python manage.py migrate
-
Create a superuser:
python manage.py createsuperuser
-
Run the development server:
python manage.py runserver
Note: Running the development server this way will not start Celery and auto-reply features will be unavailable.
-
(Optional) Run the tests:
python manage.py test
Note: You can access to the docker terminal using command:
docker-compose exec social_service sh
-
Launch Docker application:
-
Run the docker-compose:
docker-compose up --build
-
Create a superuser:
python manage.py createsuperuser
-
(Optional) Run the tests:
python manage.py test
- Swagger documentation with all API endpoints:
/api/docs
- Admin panel:
/admin
This project uses environment variables to manage sensitive
settings like API keys, database configurations, etc. Ensure
you create a .env
file based on .env.sample
in the root directory and set
the required environment variables before running the project.
- Python: 3.8+ (recommended 3.12+)
- PostgreSQL: 13.0+
- Redis: 4.0+