-
Notifications
You must be signed in to change notification settings - Fork 11.1k
-
🧩 Step 1: Tell PowerShell it's okay to run scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
🗣️ "Hey PowerShell, please allow me to run my own scripts safely."
This unlocks the ability to activate environments and run Python code.
🧩 Step 2: Go to the folder where my project lives
cd "C:\-----\Desktop\LLMs-from-scratch"
🗂️ "Let’s walk into the room where all my GenAI files are stored."
🧩 Step 3: Build a safe Python workspace
uv venv --python 3.11
🧪 "Make me a fresh lab where I can mix Python ingredients without messing up the kitchen."
This creates a .venv
folder with Python 3.11.
🧩 Step 4: Step into the lab
.\.venv\Scripts\Activate.ps1
🧼 "Put on my lab coat and start working inside the safe zone."
Now every Python command uses this clean environment.
🧩 Step 5: Remove broken tools from earlier
uv pip uninstall -y llms-from-scratch llms_from_scratch 2>$null
🧹 "Throw away any old or broken versions of my GenAI package."
🧩 Step 6: Create a special folder for my package
New-Item -ItemType Directory -Name pkg
📦 "Make a box called pkg
to hold all my GenAI chapters."
🧩 Step 7: Move my code into the box
Move-Item llms_from_scratch pkg
📤 "Put my GenAI code inside the pkg
folder so Python can find it."
🧩 Step 8: Install my code so Python knows it
uv pip install -e .
🔧 "Tell Python: this is my GenAI package, and I might change it later—please keep watching."
🧩 Step 9: Make every folder readable by Python
Get-ChildItem pkg\llms_from_scratch\ch02 -Recurse -Directory | ForEach-Object { New-Item -Path $_.FullName -Name "__init__.py" -ItemType File } New-Item pkg\llms_from_scratch\ch02\__init__.py
🧠 "Put a magic sticker (__init__.py
) on every folder so Python knows it’s part of the team."
Repeat this for:
ch03, ch04, ch05, ch06, ch07
✅ Now every chapter and subfolder is importable.
🧩 Step 10: Rename folders that confuse Python
Rename-Item "pkg\llms_from_scratch\ch0501円_main_code" "main_code"
🚫 Python doesn’t like folders starting with numbers.
✅ Renaming fixed the error: "invalid decimal literal"
🧩 Step 11: Find the tools I need
Get-ChildItem pkg\llms_from_scratch\ch05 -Recurse -Filter *.py | Select-String "def generate"
🔍 "Where’s the generate
function hiding?"
Found it in main_code/gpt_generate.py
🧩 Step 12: Fix broken imports
In gpt_generate.py
, change:
from previous_chapters import GPTModel
to:
from llms_from_scratch.ch04.gpt import GPTModel
In app.py
, change:
from llms_from_scratch.ch05 import generate
to:
from llms_from_scratch.ch05.main_code.gpt_generate import ( generate, text_to_token_ids, token_ids_to_text, )
🧩 "Tell Python exactly where to find my tools."
🧩 Step 13: Fix the model file path
In app.py
, change:
model_path = Path("..") / "01_main-chapter-code" / "gpt2-medium355M-sft.pth"
to:
model_path = Path(__file__).resolve().parent.parent / "01_main_code" / "gpt2-medium355M-sft.pth"
📁 "Show Python the correct path to my trained model file."
🧩 Step 14: Launch Chainlit!
uv run chainlit run pkg/llms_from_scratch/ch07/06_user_interface/app.py
🚀 "Start the GenAI app and open the user interface!"
✅ It worked! Chainlit opened at http://localhost:8000
🖼️ About the Image I Uploaded
The image shows a Chainlit UI giving some answers like:
- "A mammal is a bird or mammal."
- "A bird is a bird of prey."
- 🧠 What can be the problem, and how can I fix it?
🎉 Final Result
- ✅ All chapters from
ch02
toch07
are modular and importable - ✅ Chainlit connects to my model and functions
- ✅ I can run everything from one place
Beta Was this translation helpful? Give feedback.