Course: Machine Learning Engineer in the Generative AI Era
Week: 1 of 10
Date: July 21, 2025
Topic: Introduction to LLMs & Prompt Engineering
This homework assignment introduces you to Large Language Models (LLMs) and prompt engineering fundamentals. You will learn to interact with LLMs programmatically, master the CO-STAR prompt engineering framework, and begin building your course capstone project: a personalized research agent.
By the end of this assignment, you will have hands-on experience with:
- Making API calls to LLMs using Python
- Structuring effective prompts using the CO-STAR framework
- Generating and parsing structured outputs (JSON/XML)
- Implementing chain-of-thought reasoning
- Understanding model limitations and tradeoffs
- Prototyping your first AI agent
Upon completion of this assignment, students will be able to:
- Configure and authenticate with LLM APIs (cloud or local)
- Construct effective prompts using the CO-STAR framework
- Generate structured outputs from natural language inputs
- Implement chain-of-thought prompting techniques
- Evaluate and document model limitations
- Design and prototype a basic AI research agent
- Compare tradeoffs between different LLM deployment options
This assignment supports three deployment paths to accommodate different learning styles, budgets, and technical constraints:
Recommended for: Students prioritizing result quality and course alignment
- Requirements: Anthropic API key, internet connection
- Cost: ~$0.50-2.00 for this assignment
- Advantages: State-of-the-art performance, no local hardware requirements
- Model: Claude 3.5 Sonnet or Claude 3.5 Haiku
Recommended for: Budget-conscious students and those learning deployment
- Requirements: 8GB+ RAM, 10-20GB disk space
- Cost: $0 (free)
- Advantages: Unlimited experimentation, offline capability, privacy
- Recommended Models:
llama3.2:3b- Lightweight, fastllama3.1:8b- Better qualitymistral:7b- Good balanceqwen2.5:7b- Strong reasoning
Recommended for: Most students
- Use Ollama for experimentation and iteration
- Use Claude API for final deliverables
- Combines cost efficiency with quality output
- Python 3.8 or higher
- VS Code, Cursor IDE, or any IDE with Jupyter notebook support
- Basic Python proficiency (functions, dictionaries, string manipulation)
- 2-3 hours of focused work time
- Anthropic API account: https://console.anthropic.com
- Valid API key with available credits
- Stable internet connection
- Minimum 8GB RAM (16GB recommended)
- 10-20GB free disk space
- Ollama installed: https://ollama.ai
- Verification commands:
ollama pull llama3.2:3b ollama run llama3.2:3b "Hello, world!"
- Cursor IDE (https://cursor.sh) - AI-powered code editor (recommended)
- Claude Code CLI - Command-line agentic coding tool
- Git for version control
- Discord for course community
# Clone the course repository
git clone https://github.com/inference-ai-course/Homework1-Submission.git
cd Homework1-Submission# Create virtual environment
python -m venv .venv
# Activate virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
venv\Scripts\activate# Install all required packages
pip install -r requirements.txtThe requirements.txt should be set up already, but modify the optional section if needed, and feel free to use OpenAI API if you want.
# Copy the example environment file
cp .env.example .env
# Edit .env with your API key.env file is included in .gitignore and will never be committed to version control.
# Check Ollama is installed
ollama --version
# Pull recommended model
ollama pull llama3.2:3b
# Test the model
ollama run llama3.2:3b "Hello, test!"# Install Python extension if not already installed
# Open VS Code
code .
# Open homework1.ipynb
# VS Code will prompt to select a kernel - choose your venv# Open Cursor
cursor .
# Open homework1.ipynb
# Select kernel: Python Environments → venvHomework1-submission/
├── README.md
├── requirements.txt
├── .env.example
├── .gitignore
│
├── notebooks/
│ ├── 00_setup_verification.ipynb # Quick check everything works
│ ├── 01_environment_setup.ipynb # Section 1
│ ├── 02_llm_basics.ipynb # Section 2
│ ├── 03_costar_framework.ipynb # Section 3
│ ├── 04_structured_outputs.ipynb # Section 4
│ ├── 05_chain_of_thought.ipynb # Section 5
│ ├── 06_model_comparison.ipynb # Section 6
│ ├── 07_mcp_introduction.ipynb # Section 7
│ └── 08_project_kickoff.ipynb # Section 8
│
├── src/ # Shared utilities
│ ├── __init__.py
│ ├── llm_client.py # LLMClient class
│ ├── cost_tracker.py # CostTracker class
│ ├── prompt_templates.py # CO-STAR templates
│ └── utils.py # Helper functions
│
├── outputs/ # Student deliverables
│ ├── project_proposal.md
│ ├── limitations_log.md
│ └── resource_analysis.md
│
└── docs/
├── path_a_setup.md
├── path_b_setup.md
└── quick_start_guide.md
The homework is organized into 8 sections within the pre-configured Jupyter notebook (homework1.ipynb):
- Choose deployment path (Claude/Ollama/Hybrid)
- Verify installation and configuration
- Test connectivity with simple API call
- Pre-configured: Environment checks and validation cells
- Understand request/response cycle
- System vs User prompts
- Temperature and generation parameters
- Multi-model compatibility
- Pre-configured: Helper functions for API calls
- Context: Providing background information
- Objective: Defining clear goals
- Style: Formal vs casual communication
- Tone: Authoritative vs exploratory
- Audience: Target reader consideration
- Response Format: JSON, XML, plain text
- Pre-configured: Interactive exercises with templates
- JSON formatting and parsing
- XML formatting and parsing
- Schema validation with Pydantic
- Error handling strategies
- Pre-configured: Validation schemas and parsing utilities
- Theoretical foundation
- Implementation techniques
- Comparative analysis (with/without CoT)
- Multi-model reasoning comparison
- Pre-configured: Side-by-side comparison cells
- Systematic model comparison
- Speed vs quality tradeoffs
- Cost analysis (cloud vs local)
- Hallucination documentation
- Pre-configured: Comparison framework and logging templates
- Model Context Protocol overview
- Agent architecture concepts
- Tool integration planning
- Future course preview
- Pre-configured: Conceptual diagrams and code scaffolding
- Research agent definition
- Mission statement formulation
- Model selection justification
- Working prototype development
- Pre-configured: Project template with guided prompts
The notebook is designed to be run sequentially from top to bottom. Each cell builds on previous cells.
# Example: First cell sets up the environment
# DO NOT SKIP THIS CELL
import os
from dotenv import load_dotenv
load_dotenv()
print("✓ Environment loaded successfully")At the beginning of the notebook, you'll select your path:
# CONFIGURATION: Choose your path
PATH = "A" # Options: "A" (Claude), "B" (Ollama), "C" (Hybrid)
# The notebook will automatically configure based on your choice- Code cells (gray background): Run these to execute Python code
- Markdown cells (white background): Read these for instructions and context
- TODO cells: These require you to fill in code or answers
# TODO: Your code here
# Replace this comment with your implementationShift + Enter: Run current cell and move to nextCtrl/Cmd + Enter: Run current cell and stayA: Insert cell above (in command mode)B: Insert cell below (in command mode)DD: Delete cell (in command mode)M: Convert to markdown (in command mode)Y: Convert to code (in command mode)
If using Cursor IDE, you can:
- Use
Cmd/Ctrl + Kto chat with AI about code - Highlight code and ask AI for explanations
- Use AI to help debug errors
- Remember: Understand all AI-generated code before submitting
-
All 9 completed notebooks (in
notebooks/)- All code cells executed
- All TODO sections complete
- Observations documented
-
Project Proposal (
outputs/project_proposal.md)- One-sentence mission statement
- Agent description (2-3 paragraphs)
- Model selection justification
- Success criteria
-
Limitations Log (
outputs/limitations_log.md)- Minimum 3-5 documented cases
- Model name, prompt, expected/actual behavior
- Hypotheses and improvement ideas
-
Resource Analysis (
outputs/resource_analysis.md)- Path selection rationale
- Cost estimates or hardware notes
- Deployment strategy
Your submission will be considered complete when:
- ✅ All 9 notebooks completed and executed without errors
- ✅ All TODO sections filled in
- ✅ All 4 deliverable files created in
outputs/ - ✅ Working agent prototype built
- ✅ Cost tracker shows your API usage
- ✅ Reflections written in markdown cells
| Component | Weight | Criteria |
|---|---|---|
| Notebook Completion | 30% | All 9 notebooks completed, code runs |
| CO-STAR Implementation | 15% | Demonstrates all 6 components |
| Structured Outputs | 10% | Reliable JSON/XML generation |
| Model Comparison | 10% | Thoughtful analysis |
| Project Proposal | 15% | Clear, feasible, justified |
| Limitations Log | 10% | Insightful observations |
| Documentation | 10% | Clear markdown, reflections |
| Total | 100% |
- A (90-100%): Exceptional work with creative extensions
- B (80-89%): Complete work meeting all requirements
- C (70-79%): Adequate work with minor gaps
- D (60-69%): Incomplete work or significant gaps
- F (<60%): Substantial missing components
| Model | Input Cost | Output Cost | Homework Est. | Project Est. |
|---|---|---|---|---|
| Claude 3.5 Sonnet | $3/1M tokens | $15/1M tokens | $1-2 | $10-20 |
| Claude 3.5 Haiku | $1/1M tokens | $5/1M tokens | $0.50-1 | $3-8 |
- Software Cost: $0
- Hardware: May require RAM upgrade ($50-150 if needed)
- Electricity: <$0.05 per session
- Learning Phase: $0 (Ollama)
- Deliverables: $1-5 (Claude)
- Total Homework: $1-5
# 1. Clone repository
git clone https://github.com/inference-ai-course/Homework1-Submission.git
cd Homework1-Submission
# 2. Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Set up API key (if using Claude)
cp .env.example .env
# Edit .env with your API key
# 5. Open notebook in your IDE
code . # VS Code
# or
cursor . # Cursor IDE
# or
jupyter lab # Traditional Jupyter
# 6. Open homework1.ipynb and start working!-
Choose Your Path (5 min)
- Review deployment options
- Consider budget, hardware, learning goals
- Document choice in notebook Section 1
-
Verify Setup (10 min)
- Run Section 1 verification cells
- Confirm API connectivity or Ollama installation
- Troubleshoot any issues
-
Complete Core Sections (90 min)
- Work through Sections 2-7 sequentially
- Complete all TODO items
- Run experiments and document observations
-
Project Kickoff (30 min)
- Complete Section 8
- Write project proposal
- Build initial prototype
-
Documentation (20 min)
- Complete limitations log
- Write resource analysis
- Review and polish all deliverables
-
Submit (5 min)
- Verify all files in
outputs/directory - Commit and push to your repository
- Submit according to course instructions
- Verify all files in
# Solution: Install dependencies in Terminal
pip install -r requirements.txt# Solution: Check .env file, did you created it?
cat .env # Should show ANTHROPIC_API_KEY=...
# Reload environment in notebook
from dotenv import load_dotenv
load_dotenv(override=True)# Check if Ollama is running
ollama list
# Restart Ollama
# macOS/Linux: pkill ollama && ollama serve
# Windows: Restart Ollama app# Install ipykernel in your virtual environment
pip install ipykernel
# Register kernel
python -m ipykernel install --user --name=venv# Add delays between API calls
import time
time.sleep(1) # Wait 1 second between calls
# Or use exponential backoff (code provided in notebook)- Check notebook comments: Solutions often in code comments
- Review setup guides: See
docs/folder for detailed guides - Search Discord: Your issue may already be solved
- Ask in Discord: Post in #support-and-question channel
- Office hours: Attend Scott's TA office hour (OH) for live troubleshooting (not guarantee, you will have a lot to discuss in the OH)
- Email instructor: For private/urgent matters
- Anthropic API Documentation
- Anthropic Prompt Engineering Guide
- Ollama Documentation
- Ollama Models Library
- Model Context Protocol
- Course Discord Server: [Link provided by instructor]
- Course GitHub Repository: [Link provided by instructor]
- Office Hours: [Schedule provided by instructor]
- "Attention Is All You Need" - Transformer paper
- "Chain-of-Thought Prompting Elicits Reasoning" - Wei et al.
- Anthropic's prompt engineering cookbook
Q: How long should this assignment take?
A: Plan for 2-3 hours for core notebook completion, plus 1-2 hours for project brainstorming and documentation.
Q: Can I use a different IDE?
A: Yes! Any IDE that supports Jupyter notebooks will work. VS Code, Cursor, JupyterLab, and PyCharm are all fine.
Q: Do I need to use Cursor IDE?
A: No, it's optional. Any Python IDE works. Cursor is recommended for its AI features but not required.
Q: Can I work with a partner?
A: You must write your own code, but discussing concepts and collaborative debugging is encouraged.
Q: What if I get stuck?
A: Use Discord community, attend office hours, or consult documentation. Document your debugging process in the notebook.
Q: Which path should I choose?
A: Path A for best results and course alignment, Path B for zero cost and local learning, Path C for balanced approach.
Q: Can I switch paths mid-assignment?
A: Yes! Change the PATH variable in the notebook and run the setup cells again.
Q: Will smaller Ollama models work?
A: Yes, concepts are the same. Results will vary in quality but educational value remains high.
Q: My computer can't run Ollama. What should I do?
A: Use Path A (Claude API) or explore cloud options like Google Colab with GPU.
Q: The notebook won't open in my IDE
A: Ensure Jupyter extension is installed. For VS Code: Install "Jupyter" extension. For Cursor: Built-in support should work.
Q: How do I know if my setup is correct?
A: Run the verification cells in Section 1. They'll report success or specific errors.
Q: I'm getting API authentication errors
A: Check your .env file has correct key, reload environment, verify key is active in console.anthropic.com
Q: How can I minimize API costs?
A: Use Haiku for testing, implement caching, add delays, use shorter prompts during development, or use Ollama for experimentation.
Q: What if I run out of credits?
A: Switch to Ollama (Path B) for remaining work, or contact instructor about alternative arrangements.
Q: Can I use the free tier of Claude?
A: You'll need an API key with credits. Free tier chat.claude.com doesn't provide API access.
For students seeking additional depth and extra credit (up to 10%):
Implement a system that:
- Queries 3+ different models with the same prompt
- Compares responses using automated metrics
- Implements voting/consensus mechanism
- Documents which model types excel at which tasks
Build an automatic model selector that:
- Analyzes task complexity
- Estimates token usage
- Selects cheapest suitable model
- Tracks cost savings over naive approach
Complete the entire assignment in Cursor and document:
- How AI-assist helped or hindered
- Specific prompts used with Cursor AI
- Comparison with traditional coding
- Best practices discovered
Preview of Week 10:
- Set up a basic MCP server
- Implement file system tool
- Connect to Claude Desktop
- Document setup process for classmates
Create systematic measurements:
- Speed tests across models
- Quality assessments (automated + manual)
- Cost per quality point analysis
- Interactive visualization of results
Post question or answer in Discord support-and-questions channel
Submission:
- Add bonus work to
outputs/bonus_challenges.mdwith code in separate notebook section. - Post the screenshort of discord discussion to
outputs/bonus_challenges.md.
| Day | Tasks | Time |
|---|---|---|
| Day 1 | Setup complete, Section 1 | 30 min |
| Day 2 | Sections 2-3 complete | 1 hour |
| Day 3 | Sections 4-5 complete | 1 hour |
| Day 4 | Section 6 complete, start limitations log | 45 min |
| Day 5 | Section 7 complete | 30 min |
| Day 6 | Section 8 + project proposal | 1 hour |
| Day 7 | Review, polish, submit | 30 min |
- Assignment Release: After each course
- Office Hours: Wed. 7-8pm (CT)
- Submission Deadline: Sunday 11:59pm
- Late Submission Deadline: Tuesday night (with penalty)
- Up to 24 hours late (Monday): -10%
- Up to 48 hours late (Tuesday): -25%
- Beyond 48 hours: Contact instructor
- Discussing concepts and approaches
- Helping each other debug setup issues
- Sharing resources and documentation
- Collaborating on understanding course material
- Pair programming for learning (but submit individual code)
- Copying code from other students
- Submitting someone else's work as your own
- Sharing complete solutions before deadline
- Using assignment solutions from previous years
- Having someone else write your code
- You may use AI assistants (Claude, GPT, Cursor AI, etc.) to help learn concepts
- You must understand and be able to explain all submitted code
- You must document AI assistance in comments when used significantly
- You should experiment with prompting the AI effectively (it's part of learning!)
Example acceptable AI use:
# Used Claude to help debug this API call error
# Original error was "401 Unauthorized"
# Claude suggested checking .env file format
# I learned that the key needed to be on one line- Notebook Comments: Check inline comments and markdown cells first
- Setup Guides: Review
docs/folder for detailed setup instructions - Discord - Search: Your question may already be answered
- Discord - Ask: Post in
#support-and-discussionschannel- Include error messages and screenshots
- Mention your path (A/B/C) and IDE
- Share relevant code snippets
- Office Hours: Attend for live help with complex issues
- Email Instructor: For private or urgent matters only
Found a bug in course materials or the pre-configured notebook?
Submit a GitHub issue with:
- Clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Error messages and screenshots
- Your environment (OS, Python version, path, IDE)
Format: markdown
Problem: Section 3 code cell raises KeyError
Steps to Reproduce:
- Run cells in order through Section 3
- Cell 42 raises error
Error Message:
KeyError: 'response'
Environment:
- OS: macOS 14.1
- Python: 3.11.5
- Path: A (Claude API)
- IDE: VS Code
This assignment directly supports the following course-level learning outcomes:
-
LO1: Understand fundamental concepts of Large Language Models
- Assessment: Section 2, model comparison in Section 6
-
LO2: Apply prompt engineering best practices
- Assessment: CO-STAR implementation in Section 3
-
LO3: Evaluate tradeoffs in AI system design
- Assessment: Resource analysis, limitations log
-
LO4: Build functional AI applications
- Assessment: Working prototype in Section 8
-
LO5: Document and communicate technical decisions
- Assessment: Project proposal, all markdown documentation
Course materials © 2025 inferenceAI. Licensed for educational use only.
Students may:
- Use materials for completing course assignments
- Reference materials for personal learning
- Share concepts learned (not solutions) with others
Students may not:
- Redistribute course materials publicly
- Use materials for commercial purposes
- Share solutions publicly before deadline
- Anthropic for Claude API and comprehensive documentation
- Ollama Team for democratizing local LLM deployment
- Course TAs for testing materials and providing feedback
- Previous Cohorts for suggestions and improvements
- Open Source Community for tools and libraries
Special thanks to contributors who helped refine this assignment.
- v1.1 (July 21, 2025) - Updated for IDE-based workflow with pre-configured notebook
- v1.0 (July 14, 2025) - Initial release
See CHANGELOG.md for detailed version history and updates.
After completing this assignment:
- ✅ Submit all deliverables in
outputs/directory - ✅ Share your project idea in Discord
#project-ideaschannel - 📖 Read Week 2 materials on "LLM Architecture & Training Lifecycle"
- 🔬 Continue experimenting with your agent prototype
- 💬 Provide feedback on this assignment (optional survey link)
Ready to start? Open notebook folder in your preferred IDE and begin!
Questions? Check FAQ above or ask in Discord #support-discussions