This repository provides a basic API for sentiment analysis, utilizing the OpenAI API for processing text inputs. The API categorizes sentiment as positive, negative, or neutral.
- Sentiment Analysis: Analyzes and categorizes text sentiment.
- OpenAI API Integration: Uses OpenAI API for text analysis.
- User Authentication: Users must be logged in to use the API.
- Customizable Categories: Users can customize sentiment categories. Defaults are
positive
,negative
, andneutral
. - Rate Limiter: Limits usage to 100 requests per 15 minutes.
- Daily Usage Limit: Each user has 150 requests per day, renewed nightly at 00:00.
- Redis Integration: Utilizes Redis for efficient in-memory data storage and management.
express
: Web framework for Node.js.mongoose
: MongoDB object modeling tool.jsonwebtoken
: JSON Web Token implementation.bcryptjs
: Library to hash passwords.express-validator
: Middleware for validating and sanitizing user inputsdotenv
: Module to load environment variables.express-rate-limit
: Middleware to limit repeated requests.node-cron
:Task scheduler for Node.js.nodemon
: Utility to monitor for changes in Node.js applications.openai
: For sentiment analysis.redis
: In-memory data structure store.
http://localhost:3000/register
Headers:
Content-Type: application/json
Request:
{
"name": "ali",
"email":"a@gmail.com",
"password":"123456"
}
Response:
{
"success": true,
"token": ""
}
http://localhost:3000/login
Headers:
Content-Type: application/json
Request:
{
"email":"a@gmail.com",
"password":"123456"
}
Response:
{
"success": true,
"token": ""
}
http://localhost:3000/analyze
Headers:
Content-Type: application/json
Authorization: Bearer your_access_token_here
Request:
{
"text": "The customer service was not good enough, and I am very disappointed with the experience."
}
Response:
{
"success": true,
"data": "Negative"
}
http://localhost:3000/custom-sentiment-categories
Headers:
Content-Type: application/json
Authorization: Bearer your_access_token_here
Request:
{
"categories": ["Happy", "Sad", "Angry"]
}
Response:
{
"success": true,
"data": [
"Happy",
"Sad",
"Angry"
]
}
http://localhost:3000/profile
Headers:
Content-Type: application/json
Authorization: Bearer your_access_token_here
Response:
{
"success": true,
"data": {
"_id": "6666059d80df1c6f48e43c1f",
"name": "ali",
"email": "a@gmail.com",
"customSentimentCategories": [
"Happy",
"Sad",
"Angry"
],
"requestCount": 1,
"requestLimit": 2,
"createdAt": "2024-06-09T19:42:21.608Z",
"__v": 1
}
}
git clone https://github.com/carpodok/sentiment-analysis-api.git
npm install
Create a .env
file in the root directory and add the following variables:
PORT=3000
OPENAI_API_KEY=your_api_key
MONGO_URI="your_mongo_uri"
JWT_SECRET=jwt_secret
REDIS_URL=redis://127.0.0.1:6379
nem start
For development purpose with live reload, use this:
npm run dev
This project is lisenced under the MIT License.