Lesson 15 OpenAI GPT Series
Theme:

Homework

Three tasks building model-agnostic tooling and cross-provider comparison skills.

Complete all three lab exercises before starting the homework. These tasks extend the cross-provider skills from the lab.

📥 Reference Solution

⬇ lab_answer.pdf

Task 1 — Model-Agnostic LLMClient Class

Objective

Build a Python class that provides a unified interface for both OpenAI and Anthropic APIs.

Instructions

  1. Create an LLMClient class that accepts a provider parameter (“openai” or “anthropic”)
  2. Implement a chat(messages, model, max_tokens) method that returns a standardised response object with text, input_tokens, output_tokens, and model fields
  3. Handle the differences in message format (system prompt handling, response extraction)
  4. Add a stream(messages, model) method that yields text chunks from either provider
  5. Test with the same 3 prompts from the lab on both providers

Deliverable

A notebook with the LLMClient class and demonstration of the same code working with both providers.

Self-check: The same calling code works with both providers. Response format is identical regardless of provider.

Task 2 — Find 3 Tasks Where Each Model Wins

Objective

Systematically identify tasks where GPT-4o outperforms Claude and vice versa.

Instructions

  1. Design at least 10 diverse test prompts across different categories (coding, creative, analytical, factual, multilingual, etc.)
  2. Run each prompt on both GPT-4o and Claude Sonnet
  3. Rate each response on a 1–5 scale for quality, accuracy, and usefulness
  4. Identify 3 tasks where GPT-4o clearly wins and 3 where Claude clearly wins
  5. Analyse the patterns: what types of tasks favour each model?

Deliverable

A notebook with all test results, ratings, and a written analysis of the patterns observed.

Self-check: At least 10 prompts tested. Clear examples of each model winning. Analysis explains why.

Task 3 — GPT Vision Product Description Generator

Objective

Build a product description generator that uses GPT-4o vision to create marketing copy from product images.

Instructions

  1. Find 5 product images (use publicly available URLs from e-commerce sites or stock photos)
  2. Write a system prompt that instructs the model to generate e-commerce product descriptions from images
  3. For each image, generate: a product title, a 2–3 sentence description, 5 bullet-point features, and a suggested category
  4. Output the results as structured JSON
  5. Bonus: compare the same task using Claude’s vision capabilities

Deliverable

A notebook that processes 5 product images and outputs structured JSON descriptions for each.

Self-check: All 5 images produce valid JSON with title, description, features, and category. Descriptions are marketing-quality.

Submission Checklist