git-chatgpt-example.mov
- Clone this repo
- Run
$ yarn
- Run
$ node index.js
- Open browser to http://localhost:3000
Creates a NodeJS Express web service that hosts both a webpage and API.
- The webpage includes an HTML file with an input field and submit button. The input field is where the user can enter a custom pieces of text; their "prompt".
- When clicking the submit button, the input field's text value is sent to the NodeJS Express API "/completion" endpoint.
- This endpoint receives the user's prompt and passes it into OpenAI npm module to generate both a Chat GPT response and an image based on the provided prompt.
- The text and image are then rendered below the input field on the HTML webpage.
-
Create an account with OpenAI and generate an API key. You can find instructions for creating an account and generating an API key on the OpenAI website here. Once you have your API key create a
.env
file withOPENAI_API_KEY=your-key-here
inside of it -
Use the OpenAI npm module to connect to the service. You can find documentation for the OpenAI npm module here.