- Install Typescript globally:
npm install -g typescript. - The project uses dotenv NPM package to export environment variables. Rename
.env.examplefile to.envand populate the following veriables:QSTASH_TOKEN- get it hereOPENAI_API_KEY- get it hereSERVER_URL- the URL of the server which Qstash will make a request to, the server being the app. The app will be running onlocalhost:3000and a service like ngrok can be used to expose the app to the world. If ngrok is used simply runngrok http 3000in Terminal, copy the https URL and setSERVER_URLto it.
After completing the prerequisites section run npm run dev to develop with hot-reloading or npm start. This will start the application.
Make a GET request to the endpoint /generate-image with a prompt to generate an image:
curl -G --data-urlencode "prompt=the most beautiful flower" localhost:3000/generate-imageThe application will make a request to Qstash which will forward the request to OpenAI and call /image-callback endpoint with OpenAI response.
Lastly, /get-image-is-ready endpoint can be used to poll whether the image is ready using the submission id received from /generate-image response:
curl localhost:3000/get-image-is-ready?submissionId=YOUR_SUBMISSION_ID