This is a simple API powered by chat-gpt that allows you to ask GPT-5 questions and get a response locally in your dev-environment. It use custom functions that define routes for an Express.js server. The Authenticate function is defining a route for a POST request to the /api/auth endpoint, which is used to generate a JSON web token (JWT) using the generateJWTToken function and the authorization header of the request. The AskGPT function is defining a route for a POST request to the /raybags/ask-me endpoint, which is used to validate a JWT using the validateJWTToken function, then call the GPT_5 function with the question from the request body, and finally save the result to the GPT_RESPONSE model and return the response. The GetPaginatedResults function is defining a route for a GET request to the /historical-data endpoint, which is used to retrieve paginated results from the GPT_RESPONSE model. The GetAll function is defining a route for a GET request to the /historical-data-all endpoint, which is used to retrieve all the results from the GPT_RESPONSE model. The other functions are providing similar functionality for other endpoints
/api/auth
Generates a JSON web token (JWT) using the authorization
header of the request.
/raybags/v1/wizard/ask-me
Validates a JWT using the authorization
header, then calls the GPT_5
function with the question from the request body, and finally save the result to the GPT_RESPONSE model in mongodb and return the response.
/raybags/v1/wizard/data
Get paginated results:
?page=page-number ie. ?page=1
For all results.
-all
Get one item based on its id
/raybags/v1/wizard/item/:id
/raybags/v1/wizard/delete-item/:id
Handles unsupported routes.
'*'
- Clone the repository:
git clone https://github.com/raybags-web-dev/my-wizard-chat-gpt.git
- Install the dependencies:
npm install
- Start the server:
npm start
- Test the endpoints using a tool like Postman or curl.
- Express.js - The web framework used
- Node.js - The JavaScript runtime
- Jest - The testing framework
- Mongoose - The MongoDB object modeling tool and Database
- Build docker image
docker build -t my-wizard-chat-gpt .
- Run Docker container
docker run -p 8080:4200 my-wizard-chat-gpt
- You can pull the image from docker hub with
docker pull revraymondbaguma/wizard-chat:1.0.0
This will start the server inside the Docker container and map it to port 8080 on your local machine
- Raymond Baguma - Initial work - raybags-web-dev
This project is powered by chatGPT