Skip to content

Session 1: What Is Generative AI?

Synopsis

Introduces generative AI, its major categories such as text, image, code, and multimodal generation, and common real-world use cases. This session clarifies where GenAI fits within the broader AI landscape and sets expectations for what these systems can and cannot do.

Session Content

Session 1: What Is Generative AI?

Session Overview

Duration: ~45 minutes
Audience: Python developers with basic programming knowledge
Goal: Understand what Generative AI is, how it differs from traditional AI/ML, what Large Language Models (LLMs) do, and how to make your first API call using the OpenAI Responses API with Python.


Learning Objectives

By the end of this session, learners will be able to:

  • Define Generative AI in practical terms
  • Explain how Generative AI differs from traditional software and predictive ML systems
  • Describe what an LLM is at a high level
  • Identify common GenAI use cases and limitations
  • Make a basic OpenAI Responses API call in Python using gpt-5.4-mini
  • Experiment with prompt variations and observe output differences

Agenda

  1. Introduction to Generative AI
  2. How Generative AI differs from traditional programming and ML
  3. What LLMs are and how they work at a high level
  4. Common use cases, strengths, and limitations
  5. Hands-on: Your first Generative AI app in Python
  6. Hands-on: Prompting experiments
  7. Recap and discussion

1. Introduction to Generative AI

What is Generative AI?

Generative AI refers to systems that can create new content based on patterns learned from data. Instead of only classifying, predicting, or retrieving information, these systems can generate:

  • Text
  • Code
  • Images
  • Audio
  • Structured data
  • Summaries
  • Transformations of existing content

Simple definition

Generative AI is software that produces new outputs—such as text, code, or images—based on a prompt.

Examples of Generative AI

  • Writing a product description from bullet points
  • Summarizing a long email thread
  • Generating Python functions from a natural language request
  • Creating a draft blog post
  • Rewriting content in another tone
  • Extracting structured JSON from unstructured text

Why it matters for developers

Generative AI changes how developers build software:

  • Users can interact using natural language
  • Applications can produce dynamic content
  • Code can be generated, transformed, or explained
  • Workflows can be automated in more flexible ways than rule-based systems

2. Generative AI vs Traditional Programming vs Predictive ML

Traditional programming

In traditional software, developers write explicit rules.

Example

If a user enters: - age = 17 → return “minor” - age = 20 → return “adult”

The logic is deterministic and hand-coded.

def classify_age(age: int) -> str:
    if age < 18:
        return "minor"
    return "adult"


print(classify_age(17))  # minor
print(classify_age(20))  # adult

Characteristics

  • Rule-based
  • Predictable
  • Easy to test for exact outputs
  • Limited when tasks are fuzzy or language-based

Predictive machine learning

Predictive ML models learn patterns from labeled data and make predictions.

Example tasks

  • Spam detection
  • Fraud prediction
  • House price prediction
  • Image classification

These models usually output: - A class - A score - A probability - A numeric prediction

Characteristics

  • Learns from examples
  • Good for classification/regression
  • Typically does not generate rich new content

Generative AI

Generative AI learns patterns in data and produces new content that resembles what it has learned.

Example tasks

  • “Write a welcome email for a new customer”
  • “Generate SQL from this question”
  • “Summarize this support ticket”
  • “Convert these notes into JSON”

Characteristics

  • Flexible
  • Useful for open-ended tasks
  • Probabilistic rather than strictly deterministic
  • Output quality depends heavily on prompts, context, and model choice

Comparison Table

Approach Input Output Best For
Traditional programming Rules + data Deterministic result Precise business logic
Predictive ML Data Label/score/value Classification and forecasting
Generative AI Prompt + context New content Language, content creation, transformation

3. What Is an LLM?

Definition

An LLM, or Large Language Model, is a model trained on large amounts of text to predict and generate language.

At a high level, an LLM:

  • Reads input text
  • Understands patterns and relationships in language
  • Predicts what text should come next
  • Produces coherent outputs such as answers, summaries, code, and transformations

High-level intuition

You can think of an LLM as a system that has learned:

  • grammar
  • style
  • many facts and patterns
  • how instructions are expressed
  • how code and natural language relate

It does not “think” like a human, but it is very effective at producing useful language-based outputs.

Why LLMs are so useful

Because many software tasks are language-shaped:

  • Asking questions
  • Summarizing documents
  • Writing explanations
  • Extracting fields
  • Reformatting information
  • Generating code templates

Important concept: prompts

A prompt is the instruction or input you give the model.

Example prompt

Summarize this customer complaint in 3 bullet points.

The prompt shapes the output. Small changes in prompt wording can change:

  • tone
  • detail level
  • structure
  • accuracy
  • usefulness

4. Strengths and Limitations of Generative AI

Strengths

Generative AI is especially good at:

  • Drafting text quickly
  • Summarization
  • Rewriting in different tones
  • Code generation and explanation
  • Information extraction
  • Brainstorming
  • Natural language interfaces

Limitations

It is important to understand where GenAI can fail:

1. Hallucinations

The model may generate incorrect or fabricated information.

2. Inconsistency

The same prompt may produce slightly different outputs.

3. Prompt sensitivity

Small wording changes can affect results.

4. Context limits

The model can only consider a limited amount of input at once.

5. Not a replacement for validation

Generated code, facts, or decisions should be reviewed.


Good developer mindset

Treat Generative AI as:

  • a powerful assistant
  • a probabilistic system
  • something that needs guardrails, testing, and validation

Not as:

  • a guaranteed source of truth
  • a replacement for engineering judgment

5. OpenAI Responses API in Python

What we will build

A minimal Python script that:

  1. Sends a prompt to gpt-5.4-mini
  2. Receives generated text
  3. Prints the result

Prerequisites

  • Python 3.9+
  • An OpenAI API key
  • openai Python package installed

Install dependencies

pip install openai python-dotenv

Set your API key

Create a .env file:

OPENAI_API_KEY=your_api_key_here

First Python example: basic text generation

"""
session1_basic_generation.py

A minimal example showing how to call the OpenAI Responses API
using the official Python SDK and the gpt-5.4-mini model.
"""

import os
from dotenv import load_dotenv
from openai import OpenAI

# Load environment variables from .env
load_dotenv()

# Read API key from environment
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
    raise ValueError("OPENAI_API_KEY is not set. Add it to your .env file.")

# Create a client instance
client = OpenAI(api_key=api_key)

# Send a prompt to the model using the Responses API
response = client.responses.create(
    model="gpt-5.4-mini",
    input="In 2 sentences, explain what Generative AI is for a beginner Python developer."
)

# Print the generated text output
print(response.output_text)

Example output

Generative AI is a type of AI that creates new content such as text, code, images, or summaries based on patterns it has learned from data. For Python developers, it enables applications that can understand instructions in natural language and generate useful outputs dynamically.

Code walkthrough

Key ideas in the script

  • load_dotenv() loads secrets from a local .env file
  • OpenAI(api_key=...) creates the SDK client
  • client.responses.create(...) sends a request to the model
  • model="gpt-5.4-mini" selects the model
  • input="..." is the prompt
  • response.output_text gives the generated text in a convenient form

6. Hands-On Exercise 1: Your First GenAI Prompt

Objective

Write and run a Python script that asks the model to explain Generative AI in different styles.

Instructions

  1. Create a file named exercise1_intro_prompt.py
  2. Copy the code below
  3. Run it
  4. Modify the prompt and compare outputs

Exercise code

"""
exercise1_intro_prompt.py

This exercise demonstrates:
- Connecting to the OpenAI API
- Sending a prompt with the Responses API
- Printing model output
- Experimenting with prompt wording
"""

import os
from dotenv import load_dotenv
from openai import OpenAI

# Load variables from .env
load_dotenv()

# Fetch the API key securely
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
    raise ValueError("Missing OPENAI_API_KEY in environment variables.")

# Initialize the OpenAI client
client = OpenAI(api_key=api_key)

# Try changing this prompt to see how the output changes
prompt = (
    "Explain Generative AI to a Python developer who knows basic programming. "
    "Use simple language and give one real-world example."
)

# Create a response from the model
response = client.responses.create(
    model="gpt-5.4-mini",
    input=prompt
)

# Display the model's answer
print("Prompt:")
print(prompt)
print("\nModel response:")
print(response.output_text)

Suggested prompt variations

Try each of these:

Variation 1

Explain Generative AI in one sentence.

Variation 2

Explain Generative AI with a cooking analogy.

Variation 3

Explain Generative AI for a 10-year-old.

Variation 4

Explain Generative AI as if you were teaching a software engineering team.

Reflection questions

  • How does the tone change?
  • How does the complexity change?
  • Which prompt gives the clearest answer?
  • What does this tell you about prompt design?

7. Hands-On Exercise 2: Structured Output Request

Objective

Ask the model to produce information in a structured format so the response is easier to use in applications.

Why this matters

Developers often need model outputs in predictable formats like:

  • bullet lists
  • numbered steps
  • JSON
  • tables

Prompting for structure improves usability.


Exercise code

"""
exercise2_structured_prompt.py

This exercise asks the model to produce a structured explanation
of Generative AI that is easier to read and reuse.
"""

import os
from dotenv import load_dotenv
from openai import OpenAI

# Load environment settings
load_dotenv()

# Read API credentials
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
    raise ValueError("Missing OPENAI_API_KEY in environment variables.")

# Initialize SDK client
client = OpenAI(api_key=api_key)

# Prompt requesting structured output
prompt = """
Explain Generative AI for a beginner Python developer.

Return your answer with exactly these sections:
1. Definition
2. Common Use Cases
3. One Limitation

Keep the total response under 120 words.
"""

# Send the prompt to the model
response = client.responses.create(
    model="gpt-5.4-mini",
    input=prompt
)

# Print result
print(response.output_text)

Example output

1. Definition
Generative AI is a type of AI that creates new content such as text, code, images, or summaries based on patterns learned from data.

2. Common Use Cases
Writing assistants, code generation, summarizing documents, chatbots, and extracting structured information from text.

3. One Limitation
It can sometimes produce incorrect or misleading information, so outputs should be reviewed before use.

Mini challenge

Modify the prompt so the model returns:

  • a Markdown table
  • a JSON object
  • exactly 3 bullet points

8. Hands-On Exercise 3: Compare Human-Written Logic vs GenAI Output

Objective

See the difference between explicit rules and generative output.

Scenario

We want software to respond to a customer message.

Traditional approach

Use hard-coded templates.

GenAI approach

Generate a custom response from the message.


Exercise code

"""
exercise3_rules_vs_genai.py

Compare a traditional template-based response with a generated response.
"""

import os
from dotenv import load_dotenv
from openai import OpenAI

def template_reply(customer_message: str) -> str:
    """
    A simple rule-based reply function.
    In real applications, this might be expanded with more conditions.
    """
    if "refund" in customer_message.lower():
        return (
            "Hello, we received your refund request. "
            "Our support team will review it and get back to you shortly."
        )
    return (
        "Hello, thank you for contacting support. "
        "We will review your message and respond soon."
    )

# Load local environment variables
load_dotenv()

# Validate API key
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
    raise ValueError("Missing OPENAI_API_KEY in environment variables.")

# Create OpenAI client
client = OpenAI(api_key=api_key)

# Example customer message
customer_message = (
    "Hi, I was charged twice for my subscription and I would like a refund. "
    "Please help."
)

# Traditional deterministic response
rule_based = template_reply(customer_message)

# Generative AI response
prompt = f"""
You are a helpful customer support assistant.

Write a short, polite reply to this customer message:
\"{customer_message}\"

Requirements:
- Acknowledge the problem
- Be empathetic
- Do not promise a refund has been approved
- Keep it under 80 words
"""

response = client.responses.create(
    model="gpt-5.4-mini",
    input=prompt
)

genai_reply = response.output_text

# Print both for comparison
print("Customer message:")
print(customer_message)

print("\nRule-based reply:")
print(rule_based)

print("\nGenAI reply:")
print(genai_reply)

Example output

Customer message:
Hi, I was charged twice for my subscription and I would like a refund. Please help.

Rule-based reply:
Hello, we received your refund request. Our support team will review it and get back to you shortly.

GenAI reply:
Hi, I’m sorry to hear you were charged twice. Thank you for letting us know. Our support team will review your account and your refund request as quickly as possible, and we’ll follow up with next steps soon.

Discussion

Rule-based response

  • Predictable
  • Easy to control
  • Limited flexibility

GenAI response

  • More natural
  • More context-aware
  • Less predictable
  • Needs review and guardrails

9. Prompting Tips for Beginners

1. Be specific

Instead of:

Explain AI.

Use:

Explain Generative AI to a beginner Python developer in 3 bullet points.

2. Ask for format

Examples: - “Return JSON” - “Use 3 bullets” - “Keep it under 100 words” - “Write a table with two columns”

3. Provide context

Instead of:

Write an email.

Use:

Write a polite follow-up email to a customer whose issue is being investigated.

4. Add constraints

Examples: - tone - word count - audience - style - required sections

5. Iterate

Prompting is often an iterative process: - try - inspect - refine - test again


10. Common Real-World Use Cases for Developers

Content generation

  • Product descriptions
  • Documentation drafts
  • Email responses

Transformation

  • Summarization
  • Translation
  • Reformatting notes into JSON

Developer productivity

  • Code explanation
  • Boilerplate generation
  • Refactoring suggestions
  • Test case drafting

User-facing assistants

  • Help bots
  • Search assistants
  • Internal knowledge assistants

11. Recap

In this session, you learned:

  • Generative AI creates new content from prompts
  • It differs from traditional rule-based software and predictive ML
  • LLMs are language models that generate useful text and code
  • GenAI is powerful, but probabilistic and imperfect
  • Prompt design strongly affects output quality
  • You can call gpt-5.4-mini from Python using the OpenAI Responses API

12. Quick Knowledge Check

Questions

  1. What is the main difference between Generative AI and predictive ML?
  2. Why is prompt wording important?
  3. Name two strengths of Generative AI.
  4. Name two limitations of Generative AI.
  5. What Python SDK method is used in this session to send a request?

Suggested answers

  1. Predictive ML usually returns labels or numeric predictions, while Generative AI creates new content.
  2. Prompt wording shapes the tone, structure, and usefulness of the output.
  3. Summarization, drafting, code generation, rewriting, extraction.
  4. Hallucinations, inconsistency, prompt sensitivity, need for validation.
  5. client.responses.create(...)

13. Take-Home Practice

Task 1

Write a script that asks the model:

“Explain the difference between AI, ML, and Generative AI in a Markdown table.”

Task 2

Write a script that asks the model:

“Summarize this paragraph in one sentence.”

Use any paragraph from a blog post or documentation page.

Task 3

Create 3 prompts that explain Generative AI to: - a child - a manager - a Python developer

Compare the outputs.


Useful Resources

  • OpenAI Responses API guide: https://developers.openai.com/api/docs/guides/migrate-to-responses
  • OpenAI API docs: https://platform.openai.com/docs
  • OpenAI Python SDK: https://github.com/openai/openai-python
  • Python dotenv: https://pypi.org/project/python-dotenv/
  • Prompting guide: https://platform.openai.com/docs/guides/prompt-engineering

End-of-Session Summary

Generative AI is a new way of building software that can generate language, code, and other content from natural-language instructions. For Python developers, this opens the door to building assistants, summarizers, generators, and smart interfaces quickly. The key technical skill to begin with is learning how to send prompts, evaluate outputs, and iterate carefully. In the next sessions, this foundation can expand into prompt engineering, structured outputs, tools, agents, and multi-step workflows.


Back to Chapter | Back to Master Plan | Next Session