This project is a Node.js server built with Express.js and OpenAI's API for text moderation. It provides a REST API for moderating user-generated content, such as messages or comments.
Before you can run the server, you'll need to:
-
Have an OpenAI API key. You can sign up for an API key here.
-
Install Node.js and npm on your local machine.
- Clone the repository:
git clone https://github.com/hppanpaliya/openai-text-moderation-server
cd openai-text-moderation-server
- Install dependencies:
npm install
- Create a
.env
file in the root directory of the project and add your OpenAI API key:
OPENAI_API_KEY={your_api_key}
- Run the server:
npm start
The server will start on port 4000 by default. You can change the port by setting the PORT
environment variable.
The server provides the following endpoints:
-
GET /
: A simple endpoint to check server that returns "Hello World!". -
POST /moderate
: An endpoint for moderating user-generated content. Expects a JSON payload with the following properties: -
userId
: A unique identifier for the user who generated the content. -
message
: The text message to be moderated.
Returns a JSON payload with a single property, output
, which contains the moderated message.
Contributions are welcome! If you find a bug or have an idea for a new feature, please open an issue or a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.