A high-performance, asynchronous content moderation API powered by FastAPI and Google Gemini AI.
Sentinel implements a non-blocking architecture using FastAPI's BackgroundTasks:
- Ingest: API receives text payload and saves it to MySQL with status
PENDING. - Acknowledge: Returns a
task_idto the client immediately. - Process: A background worker thread sends the payload to selected Google's Gemini model.
- Update: The result (Safe/Unsafe, Category, Confidence) is written back to the database asynchronously.
- API Framework: FastAPI (Python)
- AI Model: Google Gemini Flash/Pro (can be configured in
.env) - Database: MySQL 8.0
- Containerization: Docker & Docker Compose
-
Clone the repository:
git clone https://github.com/damashiai/sentinel.git cd sentinel -
Configure Environment: Create a
.envfile in the root directory:# Database Config MYSQL_ROOT_PASSWORD=secret MYSQL_DATABASE=sentinel_db MYSQL_USER=sentinel_user MYSQL_PASSWORD=sentinel_pass # AI Config GEMINI_API_KEY=your_google_api_key_here GEMINI_MODEL=models/gemini-flash-latest
-
Launch:
docker-compose up --build
The API will be available at
http://localhost:8000/docs.
-
Install Dependencies:
python -m venv venv source venv/bin/activate # or venv\Scripts\activate on Windows pip install -r requirements.txt
-
Setup Database: Ensure you have a MySQL server running (or have a cloud MySQL instance running) and update the
DATABASE_URLin your.envfile to point tolocalhost(or your cloud MySQL DB URL). -
Run Server:
uvicorn main:app --reload
POST /analyze
{
"text": "You are stupid and I hate you."
}GET /status/{task_id}
{
"id": 1,
"status": "COMPLETED",
"result": {
"safe": false,
"category": "hate_speech",
"confidence": 0.99
}
}MIT License.