FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add Day 1 AI developer course materials by commitRahul · Pull Request #1 · commitRahul/basic-programs · GitHub

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .example  (1) .md  (3) .py  (6) .txt  (1) dotfile  (1) All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions python/ai-dev-course/.env.example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copy to .env on Day 3 when we call real APIs
# cp .env.example .env

OPENAI_API_KEY=sk-your-key-here
4 changes: 4 additions & 0 deletions python/ai-dev-course/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv/
.env
__pycache__/
*.pyc
41 changes: 41 additions & 0 deletions python/ai-dev-course/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 90-Day AI Developer Course

A hands-on path from software developer to LLM-focused AI engineer.

## Structure

```
ai-dev-course/
├── README.md # This file
├── requirements.txt # Shared dependencies
├── .env.example # API keys template (Day 3+)
├── day-01/ # Week 1, Day 1
├── day-02/ # Week 1, Day 2 (coming)
└── ...
```

## Setup (once)

```bash
cd python/ai-dev-course
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
```

**Linux note:** If `venv` fails, install it first: `sudo apt install python3-venv`
**Alternative:** `pip install -r requirements.txt` in your user environment also works for Day 1.

## Daily rhythm (~3 hours)

1. **Hour 1** — Read the lesson, run demo scripts, ask questions
2. **Hour 2** — Complete the exercise(s)
3. **Hour 3** — "Explain back" check + stretch goal (optional)

## Progress

| Day | Topic | Status |
|-----|-------|--------|
| 1 | LLM basics + tokens | Done |
| 2 | Prompts + parameters | In progress |
| 3 | First API call | — |
65 changes: 65 additions & 0 deletions python/ai-dev-course/day-01/01_token_explorer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""
Day 1 Demo: Token Explorer

Shows how text is split into tokens — the fundamental unit of LLM cost and limits.

Run: python day-01/01_token_explorer.py
"""

import tiktoken

# cl100k_base is used by GPT-4, GPT-3.5-turbo, and many modern models
ENCODING = tiktoken.get_encoding("cl100k_base")

SAMPLES = [
"Hello, world!",
"The quick brown fox jumps over the lazy dog.",
"ChatGPT",
"AI",
"def hello(): print('hi')",
"🚀 emoji costs extra tokens sometimes",
"Bonjour le monde", # French
"こんにちは", # Japanese
]


def count_tokens(text: str) -> int:
return len(ENCODING.encode(text))


def show_tokens(text: str) -> None:
tokens = ENCODING.encode(text)
decoded = [ENCODING.decode([t]) for t in tokens]
return tokens, decoded


def main() -> None:
print("=" * 60)
print("DAY 1: TOKEN EXPLORER")
print("=" * 60)
print()
print("Model encoding: cl100k_base (GPT-4 / GPT-3.5 family)")
print()

for text in SAMPLES:
tokens, pieces = show_tokens(text)
print(f"Text: {text!r}")
print(f"Tokens: {len(tokens)}")
print(f"Pieces: {pieces}")
print("-" * 40)

# Cost preview (rough GPT-4o-mini pricing as of 2024–2025)
sample = "Explain recursion in Python in two sentences."
n = count_tokens(sample)
cost_per_1m_input = 0.15 # USD per 1M input tokens (example rate)
cost = (n / 1_000_000) * cost_per_1m_input
print()
print("COST PREVIEW (example rates, check current pricing):")
print(f" Prompt: {sample!r}")
print(f" Tokens: {n}")
print(f" Est. input cost: ${cost:.8f} per request")


if __name__ == "__main__":
main()
122 changes: 122 additions & 0 deletions python/ai-dev-course/day-01/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Day 1 — What Is an LLM? + Your First AI Script

**Time:** ~3 hours
**Goal:** Understand what LLMs are at a practical level, set up your environment, and explore **tokens** (the unit LLMs actually consume).

---

## Hour 1: Concepts

### 1.1 What is a Large Language Model (LLM)?

An LLM is a neural network trained on massive text to **predict the next token** (word piece).
Stack billions of those predictions and you get something that *looks* like understanding.

```
Input: "The capital of France is"
Model: predicts → " Paris"
```

**Key insight:** It does not "look up facts" in a database. It predicts likely text based on patterns seen during training.

### 1.2 Tokens — the real currency

LLMs don't read words; they read **tokens** (subword chunks).

| Text | Approx. tokens |
|------|----------------|
| `"Hello"` | 1 |
| `"Hello, world!"` | 4 |
| `"ChatGPT"` | 2 |
| `"Python"` | 1 |
| `"supercalifragilisticexpialidocious"` | ~8 |

**Why tokens matter:**
- **Cost** — APIs charge per token (input + output)
- **Limits** — context window = max tokens in one request
- **Prompt design** — shorter prompts = cheaper + more room for answers

### 1.3 Context window

The **context window** is how much text the model can "see" at once (prompt + response combined).

Modern models: roughly 8K–200K+ tokens depending on model.

If your prompt + documents + answer exceed the window → truncation or errors.

### 1.4 Temperature (preview — we use this on Day 2)

| Temperature | Behavior |
|-------------|----------|
| `0.0` | Deterministic, same answer each time |
| `0.7` | Balanced creativity (common default) |
| `1.0+` | More random, creative, less predictable |

### 1.5 System vs user messages (preview — Day 2)

```
System: "You are a helpful Python tutor. Be concise."
User: "Explain list comprehensions."
```

The **system prompt** sets behavior; the **user message** is the actual request.

---

## Hour 1: Run the demo

From the course root:

```bash
cd python/ai-dev-course
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python day-01/01_token_explorer.py
```

Try editing the `SAMPLES` list in the script and re-run. Watch how token counts change.

---

## Hour 2: Your exercise

Open `day-01/exercises/exercise_01_tokens.py` and complete the three TODOs.

Run it:

```bash
python day-01/exercises/exercise_01_tokens.py
```

All tests should print `PASS`.

---

## Hour 3: Explain back (answer in your own words)

Reply to your instructor (me) with answers to these three questions:

1. **What is a token, and why do AI developers care about token count?**
2. **In one sentence, how does an LLM generate text?**
3. **What happens if your prompt + documents are larger than the context window?**

Optional stretch: Add 5 strings of your own to the token explorer and note which surprised you (longer/shorter than expected).

---

## Key terms (Day 1)

| Term | Meaning |
|------|---------|
| **LLM** | Large Language Model — predicts next tokens |
| **Token** | Subword unit the model reads/writes |
| **Context window** | Max tokens per request |
| **Inference** | Running the model to get a response (vs training) |
| **Prompt** | Text you send to the model |

---

## Tomorrow (Day 2)

Prompt engineering basics: system prompts, temperature, and your first **local** prompt playground (still no API key needed for most exercises).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
"""
Day 1 Exercise: Token Basics

Complete the three functions below, then run:
python day-01/exercises/exercise_01_tokens.py

Goal: prove you understand tokens by implementing simple helpers.
"""

import tiktoken

ENCODING = tiktoken.get_encoding("cl100k_base")


def count_tokens(text: str) -> int:
"""Return the number of tokens in text."""
# TODO 1: use ENCODING.encode(text) and return the length
return len(ENCODING.encode(text))


def fits_in_context(text: str, max_tokens: int) -> bool:
"""Return True if text uses at most max_tokens."""
# TODO 2: use count_tokens
return count_tokens(text) <= max_tokens


def truncate_to_tokens(text: str, max_tokens: int) -> str:
"""
Return text truncated to at most max_tokens.
Hint: encode → slice [:max_tokens] → decode
"""
# TODO 3: truncate without breaking mid-token (encode/decode handles this)
return ENCODING.decode(ENCODING.encode(text)[:max_tokens])
# raise NotImplementedError("TODO 3: implement truncate_to_tokens")


# --- Tests (do not edit below) ---

def run_tests() -> None:
tests_passed = 0
tests_total = 0

def check(name: str, condition: bool) -> None:
nonlocal tests_passed, tests_total
tests_total += 1
status = "PASS" if condition else "FAIL"
print(f" [{status}] {name}")
if condition:
tests_passed += 1

print("Running tests...\n")

# Test count_tokens
check("count_tokens: empty", count_tokens("") == 0)
check("count_tokens: hello", count_tokens("hello") == 1)
check("count_tokens: hello world", count_tokens("hello world") == 2)

# Test fits_in_context
check("fits: short text", fits_in_context("hi", 10) is True)
check("fits: exact limit", fits_in_context("hello world", 2) is True)
check("fits: over limit", fits_in_context("hello world", 1) is False)

# Test truncate_to_tokens
check("truncate: under limit", truncate_to_tokens("hello", 10) == "hello")
check("truncate: exact", truncate_to_tokens("hello world", 2) == "hello world")
truncated = truncate_to_tokens("hello world foo", 2)
check("truncate: cuts", truncated == "hello world")
check("truncate: empty", truncate_to_tokens("anything", 0) == "")

print(f"\n{tests_passed}/{tests_total} tests passed.")
if tests_passed == tests_total:
print("\nDay 1 exercise complete! Answer the explain-back questions in day-01/README.md")
else:
print("\nKeep going — fix failing tests before moving to Day 2.")


if __name__ == "__main__":
run_tests()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
"""
Day 1 Solution (for self-check after you try the exercise)

Only open this AFTER attempting exercise_01_tokens.py yourself.
"""

import tiktoken

ENCODING = tiktoken.get_encoding("cl100k_base")


def count_tokens(text: str) -> int:
return len(ENCODING.encode(text))


def fits_in_context(text: str, max_tokens: int) -> bool:
return count_tokens(text) <= max_tokens


def truncate_to_tokens(text: str, max_tokens: int) -> str:
token_ids = ENCODING.encode(text)
return ENCODING.decode(token_ids[:max_tokens])
Loading

Back | FazBrowse Home | New Git URL