This is a simple Node.js application that provides a chat interface with the OpenAI GPT API.
- Node.js and npm installed on your machine.
- Clone the repository (or download the files).
- Open a terminal in the project directory.
- Install the dependencies:
npm install
-
Create a
.envfile in the root of the project. -
Add your OpenAI API key to the
.envfile:OPENAI_API_KEY=your_openai_api_keyReplace
your_openai_api_keywith your actual key. -
Add your Admin API key for secure endpoints:
ADMIN_API_KEY=your_secret_admin_key
To start the server, run the following command in your terminal:
node index.jsThe server will start on port 3000 by default.
You can interact with the chat API by sending a POST request to the /chat endpoint.
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, how are you?"}'{
"response": "I am an AI assistant, so I don't have feelings, but I'm here to help you!"
}You can view the source code of the application by sending a GET request to the /source-code endpoint. This requires a valid ADMIN_API_KEY to be sent in the X-API-Key header.
curl http://localhost:3000/source-code?file=index.js \
-H "X-API-Key: your_secret_admin_key"