Generative AI Systems
Ketan Mayer-Patel
UNC Department of Computer Science
COMP 426: Modern Web Programming (Fall 2026)
Module 4: Backend
Lecture 18
Recap
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Another class of backend technologies has recently become increasingly important.
Generative AI ✨
Companies across all economic sectors are racing to adopt these features and develop more powerful Generative AI systems.
Recap
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Generative AI
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
�����Gen AI “Model”
Input prompt�(a question)
The AI generates new content based on this prompt
Generative AI
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
�����Gen AI “Model”
Input prompt�(a question)
The AI generates new content based on this prompt
Generative AI
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
The Basics - How LLMs work
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Take n tokens
Input tokens into the language model.
Generate 1 new token back
What is a token?
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Tokens
Wow
,
Gener
ative
AI
is
so
cool
!
The Basics - How LLMs work
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Take n tokens
Input tokens into the language model.
Generate 1 new token back
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
Take n tokens
…
P=
Next Token
Generate 1 new token back
The language model predicts the next token.
Basics - How Generative Language Models Work
M4: Backend
L18
Keep
calm
and
carry
0.72
0.16
on
the
0.07
it
0.02
an
on
p refers to the predicted probability that a token is the correct next response.
But wait - aren’t GPT’s responses much longer?
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
The
`
quick
The
quick
`
brown
The
quick
brown
`
fox
The
quick
brown
fox
`
jumps
The
quick
brown
fox
jumps
`
over
The
quick
brown
fox
jumps
over
`
the
The
quick
brown
fox
jumps
over
the
`
lazy
The
quick
brown
fox
jumps
over
the
lazy
`
dog
The language model generates one new token at a time.
The old input + new token is passed as input for the next iteration.
Discuss: What problem might arise because tokens are generated one-by-one?
Text Generation
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Hallucinations
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
The
`
quick
The
quick
`
brown
The
quick
brown
`
fox
The
quick
brown
fox
`
bought
The
quick
brown
fox
bought
`
the
The
quick
brown
fox
bought
the
`
new
The
quick
brown
fox
`
video
The
quick
brown
fox
`
game
One incorrectly generated token can essentially corrupt the rest of the response.
bought
the
new
bought
the
new
video
wrong next token chosen
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
The
quick
brown
fox
game
bought
the
new
video
The
quick
brown
fox
jumps
over
the
lazy
dog
Hallucinations
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
TL;DR - You cannot blindly trust the output of AI models!
M4: Backend
L18
LLMs
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
AI Servers
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Router
React, etc
Next App
Vercel (or Dev) Server
Next Server Functionality
Supabase
Client
Drizzle
OpenAI
GPT-5
Discuss: What would connect to the OpenAI server?
AI Servers
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Router
React, etc
Next App
Vercel (or Dev) Server
Next Server Functionality
Supabase
Client
Drizzle
OpenAI
GPT-5
Our server can communicate with GPT to generate text in response to an API request.
Like with our database, we let our server connect to OpenAI so we do not expose our API key.
How do we structure our requests?
Prompts
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Prompt Engineering
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
M4: Backend
L18
Attendance Check
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
Consider this GPT prompt.
Rewrite the prompt to use prompt engineering best practices.
Submit to GradeScope!
Here is my essay draft:�[paste essay here]�
Fix it and make it sound better but don’t change too much. Also, make it longer but not too long, and more formal but not too formal. And don’t change the meaning but make it different.
!
M4: Backend
L18
Improving the Prompt
COMP 426: Modern Web Programming (Fall '26)
Generative AI Systems
Here is my essay draft:�[paste essay here]�
Fix it and make it sound better but don’t change too much. Also, make it longer but not too long, and more formal but not too formal. And don’t change the meaning but make it different.
Here is my essay draft, denoted within triple backticks: �Essay: ```�[paste essay here].
```
Please do the following:
1. Improve grammar and clarity.
2. Expand each paragraph by 2–3 sentences to add depth.
3. Adjust the tone to be moderately formal (like an academic essay for high school).
4. Return the revised essay as full text.
M4: Backend
L18