This is a node server built to serve as a API resource to interact with ChatGPT inside of the Vtiger CRM.
You need to have Node.js and npm installed on your machine. If you don't have them installed, you can download them from here.
- Fork and clone the repo.
- Navigate to the project directory.
- Run
npm install
to install the dependencies. - Proceed to Docker Section to deploy with Docker.
- /api/chat/article - POST request that takes in a message and returns a JSON object.
-
/api/chat/article/post - POST request that posts generated article to specified wordpress site.
-
/api/chat/post/contact - POST request generates a Oxygen JSON output for a contact page.
-
/api/chat/post/about - POST request generates a Oxygen JSON output for a about page.
-
/api/test - GET request to calls a free api for testing purposes.
Interaction with the OpenAI API is made easy with this simple Node server.
- Edit the GPT model to your liking in server/server.js IMPORTANT NOTE: CHANGING THE MODEL CAN HAVE UNFORSEEN BUGS
- Using the /api/chat/article endpoint, send a post request with a body including a message for chat completion
HTTP Response will be content from a JSON object.
Included in the root directory are a Dockerfile and a docker-compose.yml. This allows the server to be spun up as a docker container locally, or on a hosted service that supports docker deployment.
- Ensure docker daemon is installed on the local machine (Docker Desktop).
- Ensure you have a api_txt file in the root directory containing Openai api key.
- Ensure you have a .env file with Port variable.
- Change
// Check if the Docker secret file exists
if (fs.existsSync('/etc/secrets/openai_api_key')) {
// Read the API key from the Docker secret
OPENAI_API_KEY = fs.readFileSync('/etc/secrets/openai_api_key', 'utf8').trim();
} else {
// Log error
console.log("No api key")
}
To
// Check if the Docker secret file exists
if (fs.existsSync('/run/secrets/openai_api_key')) {
// Read the API key from the Docker secret
OPENAI_API_KEY = fs.readFileSync('/run/secrets/openai_api_key', 'utf8').trim();
} else {
// Log error
console.log("No api key")
}
- Run
docker-compose up
to spin up the image and container via docker-compose.yml file. - The server should now be running locally on specified port and can be tested with end points.
Render will be used as a example of hosted Docker deployment.
- Click on the New + button to create a new deployed asset.
- Choose Web service option.
- Link github repo.
- Ensure runtime displays "Docker".
- Add .env PORT variable and Docker secret file labeled as "open_ai_key".
After deployment, test end points to verify deployment success.
API keys are valuable and are not secure when placed inside of a .env file of the docker container. For this reason, you want to create a docker secret file for added security. IMPORTANT NOTE: This method is not entirely secure. For maximum security, use docker swarm.
Once you are on the workflow designer, set up a web-service call and associated action once data is received.
Use the parameter section and name it "message". Make the value your prompt to GPT. IMPORTANT NOTE: GPT is in JSON mode so your prompt needs to say, "Return a JSON object with the following structure:"