Generative AI Introduction

Generative AI · Lesson 1 of 28 7 min read Updated

You may already have asked a chatbot to write a leave application, explain a maths step or fix an error in your code. Tools like these are called generative AI, and they have quickly become part of everyday study and office work.

In this lesson you will learn what generative AI is, how it differs from the AI that came before it, what it is good and bad at, and the three main ways people use it. The rest of this course builds on these ideas, from writing better prompts to building small AI tools in Python.

What is generative AI?

Generative AI is software that creates new content when you ask for it: text, images, audio, video or computer code. You give it an instruction, called a prompt, and it produces something that did not exist before.

Older AI systems were mostly predictive. They took an input and chose from a fixed set of answers: "spam" or "not spam", "fraud" or "normal", a price, a ranking. A generative system does not pick from a list. It writes a fresh answer every time, which is why the same prompt can give different replies.

The small program below shows the difference in miniature. The first function puts a review into a fixed category. The second one builds a new reply, and the reply changes with the random seed. Real generative AI is vastly more capable, but the contrast between choosing a label and producing new content is the same.

PythonRun it yourself
import random

def classify(review):
    """Predictive style: put the input into one of a few fixed categories."""
    good_words = {"tasty", "fresh", "fast", "friendly"}
    words = set(review.lower().replace(",", "").replace(".", "").split())
    return "positive" if words & good_words else "needs attention"

def generate_reply(seed):
    """Generative style: produce new text, which can differ each time."""
    rng = random.Random(seed)
    openings = ["Thank you", "Thanks a lot", "Many thanks"]
    middles = ["for visiting our Jaipur cafe", "for trying our masala chai", "for your kind words"]
    endings = ["See you again soon.", "Do visit us this weekend.", "Your feedback helps us improve."]
    return f"{rng.choice(openings)} {rng.choice(middles)}. {rng.choice(endings)}"

review = "Fresh samosas and friendly staff."
print("Label:", classify(review))
for seed in [1, 2, 3]:
    print("Reply:", generate_reply(seed))
Output
Label: positive
Reply: Thank you for your kind words. See you again soon.
Reply: Thank you for visiting our Jaipur cafe. See you again soon.
Reply: Thank you for your kind words. Your feedback helps us improve.

Where generative AI fits

You will hear several overlapping terms. Each one sits inside the one before it:

TermMeaningExample
Artificial intelligence (AI)Any computer system that does tasks we link with human thinkingA chess program
Machine learning (ML)AI that learns patterns from data instead of following hand-written rulesA spam filter
Deep learningMachine learning with large neural networksFace unlock on a phone
Generative AIDeep learning models that create new contentA chatbot writing an email

The most important kind of generative AI for this course is the large language model (LLM): a very large neural network trained on huge amounts of text so that it can read and write language. ChatGPT, Claude, Gemini and Microsoft Copilot are all built on LLMs. Image generators use related models trained on pictures. If you want the mathematics behind these models, see LLMs & Generative AI in the Machine Learning course. This course focuses on using them well.

A very short history helps explain why this feels so sudden. In 2017, Google researchers published the transformer, the network design that almost every modern LLM uses. Models grew larger every year, and in November 2022 OpenAI released ChatGPT to the public. Within months, millions of people were using an AI assistant, and every large technology company followed with its own.

What it does well, and what it does badly

Generative AI is excellent at language work: drafting, rewriting, summarising, translating, explaining, brainstorming and writing code. It works fast, never gets tired of your follow-up questions, and can adjust its tone for a teacher, a customer or a child.

It also has real weaknesses that you must keep in mind from day one:

  • It can be confidently wrong. It predicts text that sounds right. It can invent facts, dates, laws or book titles. This is called a hallucination.
  • It may not know recent events. A model learns from data collected up to a cut-off date, unless the tool also searches the web.
  • It does not understand your situation unless you describe it. Vague prompts get vague answers.
  • It can repeat unfair patterns from the text it learned from.
  • Whatever you type may be stored by the service, so private data needs care.

A good rule: treat AI output as a first draft from a fast, well-read helper who sometimes makes things up. You stay responsible for the final work.

Three ways people use generative AI

  1. Chat apps. You open ChatGPT, Claude, Gemini or Copilot in a browser or phone app and type (or speak) your request.
  2. Built into other tools. AI features appear inside email, word processors, spreadsheets, phone keyboards, photo editors and code editors, so you use AI without opening a separate app.
  3. Through code. Developers send prompts to a model over the internet using an API (application programming interface) and use the reply inside their own app, for example a college FAQ bot.

For the third way, a program sends a small JSON message like this one to the AI provider. You will write real code like this in Using AI APIs from Python.

JSON
{
  "model": "claude-sonnet-5-5",
  "max_tokens": 300,
  "messages": [
    {"role": "user", "content": "Write a two-line thank-you reply to a customer who liked our samosas."}
  ]
}

Common mistakes

  • Treating AI answers as facts. Always check names, numbers, dates and quotes before you use them.
  • Typing one vague line and giving up. Clear, detailed prompts make a huge difference. You will learn how in the next lessons.
  • Pasting private information. Do not share passwords, Aadhaar numbers, customer data or company secrets with public AI tools.
  • Letting AI do all your thinking. Use it to speed up your work, not to replace your own understanding.

Key points

  • Generative AI creates new text, images, audio, video and code from a prompt.
  • Predictive AI chooses from fixed answers; generative AI writes fresh output each time.
  • Large language models (LLMs) power assistants such as ChatGPT, Claude, Gemini and Copilot.
  • It is strong at language work but can hallucinate, miss recent events and repeat bias.
  • People use it through chat apps, inside other tools, and through APIs from code.

Exercise

Run the first example. Then add a fourth list called signoffs with three short sign-offs such as "Team Chai Point", and change generate_reply so each reply ends with one of them. Print replies for the seeds 4, 5 and 6. Finally, write one sentence explaining why the reply changes but the label does not.

Show solution
Python
import random

def generate_reply(seed):
    rng = random.Random(seed)
    openings = ["Thank you", "Thanks a lot", "Many thanks"]
    middles = ["for visiting our Jaipur cafe", "for trying our masala chai", "for your kind words"]
    endings = ["See you again soon.", "Do visit us this weekend.", "Your feedback helps us improve."]
    signoffs = ["Team Chai Point", "The Jaipur Cafe family", "Meera, Cafe Manager"]
    return (f"{rng.choice(openings)} {rng.choice(middles)}. "
            f"{rng.choice(endings)} - {rng.choice(signoffs)}")

for seed in [4, 5, 6]:
    print(generate_reply(seed))
Output
Thank you for trying our masala chai. See you again soon. - Meera, Cafe Manager
Many thanks for trying our masala chai. Your feedback helps us improve. - The Jaipur Cafe family
Many thanks for visiting our Jaipur cafe. Do visit us this weekend. - The Jaipur Cafe family

The reply is built from random choices, so a new seed gives new text. The label comes from a fixed rule with only two possible answers, so the same review always gets the same label.

Quick Quiz

1. What makes an AI system "generative"?

2. Which of these is a large language model used for?

3. What is a hallucination?

4. A developer wants a college website to answer questions with AI. Which way of using AI fits best?

Learn Generative AI with a mentor

Free lessons get you started. Our AI Training & Workshops training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call