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.pdfTask 1 — Model-Agnostic LLMClient Class
Objective
Build a Python class that provides a unified interface for both OpenAI and Anthropic APIs.
Instructions
- Create an
LLMClientclass that accepts aproviderparameter (“openai” or “anthropic”) - Implement a
chat(messages, model, max_tokens)method that returns a standardised response object withtext,input_tokens,output_tokens, andmodelfields - Handle the differences in message format (system prompt handling, response extraction)
- Add a
stream(messages, model)method that yields text chunks from either provider - 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
- Design at least 10 diverse test prompts across different categories (coding, creative, analytical, factual, multilingual, etc.)
- Run each prompt on both GPT-4o and Claude Sonnet
- Rate each response on a 1–5 scale for quality, accuracy, and usefulness
- Identify 3 tasks where GPT-4o clearly wins and 3 where Claude clearly wins
- 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
- Find 5 product images (use publicly available URLs from e-commerce sites or stock photos)
- Write a system prompt that instructs the model to generate e-commerce product descriptions from images
- For each image, generate: a product title, a 2–3 sentence description, 5 bullet-point features, and a suggested category
- Output the results as structured JSON
- 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
- Task 1: LLMClient class with unified interface for both providers
- Task 2: 10+ prompts tested on both models; 3 wins each identified with analysis
- Task 3: 5 product images processed with structured JSON output
- All code runs without error after kernel restart + run all