Getting Started

Generative AI Introduction

Understand what generative AI is, how it works, and the different types of generative models.

What is Generative AI?

Generative AI refers to AI systems that can create new content — text, images, audio, video, code, and more — based on patterns learned from training data.

How Generative AI Works

Traditional AI: Input → Classification/Prediction → Output label

Generative AI: Input (prompt) → Generate new content → Output

The model learns the distribution of the training data and can sample from that distribution to create new, similar content.

Types of Generative AI

Text Generation (LLMs)

  • GPT-4, Claude, Gemini, Llama
  • Generate human-like text, answer questions, write code

Image Generation

  • Diffusion models: DALL-E, Stable Diffusion, Midjourney
  • GANs (Generative Adversarial Networks): older approach

Audio/Music Generation

  • Generate speech, music, sound effects

Video Generation

  • Sora (OpenAI), Runway, Pika

Code Generation

  • GitHub Copilot, Cursor, Claude Code

The Generative AI Revolution

2022-2024 saw an explosion of generative AI capabilities, with models achieving human-level performance on many creative and analytical tasks.

Example

python
# Working with generative AI models
import anthropic

# Initialize the client
client = anthropic.Anthropic()  # Uses ANTHROPIC_API_KEY environment variable

# Basic text generation
message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Write a short poem about generative AI."}
    ]
)

print(message.content[0].text)

# System prompt for specialized behavior
response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=500,
    system="You are a professional Python developer. Respond with clean, well-commented code.",
    messages=[
        {"role": "user", "content": "Write a function to check if a string is a palindrome."}
    ]
)

print(response.content[0].text)

# Multi-turn conversation
conversation = []

def chat(user_message):
    conversation.append({"role": "user", "content": user_message})
    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=500,
        messages=conversation
    )
    assistant_message = response.content[0].text
    conversation.append({"role": "assistant", "content": assistant_message})
    return assistant_message

# Example conversation
print(chat("What is a neural network?"))
print(chat("How does it differ from a decision tree?"))
Try it yourself — PYTHON