# Building a Node.JS OpenAI (3.0) app with NextJS (12.1)
# Introduction
In this lab we will build a "pet name generator web app" wich will be described in this tutorial. The OpenAI API quickstart tutorial (opens new window) refers to the current version of the OpenAI API and no longer describes this app.
You can see a solution deployed at netlify: https://nextjs-oai.netlify.app/ (opens new window)
The code uses Next.js (opens new window) framework version 12 with React (opens new window) version 17 and OpenAI npm module version 3:
➜ nextjs-solution git:(main) ✗ jq '.dependencies' package.json
{
"next": "^12.1.6",
"openai": "^3.0.0",
"react": "17.0.2",
"react-dom": "17.0.2"
}
2
3
4
5
6
Next.js (opens new window) is a framework on top of React that handles the tooling and configuration needed for React, and provides additional structure, features, and optimizations for your application.
- OpenAI API quickstart tutorial Node.js example (opens new window).
- Or repo ULL-MII-SYTWS/nextjs-solution (opens new window)
You can see a solution deployed at netlify: https://nextjs-oai.netlify.app/ (opens new window)
The code uses the Next.js (opens new window) framework with React (opens new window).
# First Steps
See section OpenAI First Steps in this tutorial.
# Setup
See section Set up and run in this tutorial.
# Web Development with Next.js
See section Web Development with Next.js in this tutorial.
# Exercise: Deploy at Netlify
Deploy the app at Netlify. For the details, see section Deploying a Next.js app to Netlify in this tutorial.
# Exercise: Deploy the app to Vercel
Deploy the app at Vercel. Follow the instructions at the tutorial Deploying to Vercel in this tutorial.
# Exercise: Get images from OpenAI
Add routes to the app:
- On the first route
/pet
leave the current service - On the second route
/image
add functionality to get an image from OpenAI and display it in the page. - Update the landing page and navigation links
- Add a 404 page
- Consider the opportunity to solve it using a dynamic route
The youtube video Build An AI Image Generator With OpenAI & Node.js can help:
# Exercise: Implement the Prompt Engineering Agent
Implement the prompt engineering agent described in previous lab prompt engineering
# References
- Netlify (opens new window)
- Next.js (opens new window)
- React (opens new window)
- Netlify CLI (opens new window)
- Next.js on Netlify (opens new window)
- Deploying a Next.js app to Vercel (opens new window)
- A solution deployed at netlify https://nextjs-oai.netlify.app/ (opens new window)
- Here is YouTube video explaining a project similar to the one described in this lab: Build An AI Image Generator With OpenAI & Node.js (opens new window)
- Repo ULL-MII-SYTWS/nextjs-dynamic-routes (opens new window)
- NextJS official examples folderx (opens new window)