Launching refreshed version of LLM Engineering weeks 1-4 - see README
This commit is contained in:
204
setup/SETUP-PC.md
Normal file
204
setup/SETUP-PC.md
Normal file
@@ -0,0 +1,204 @@
|
||||
# LLM Engineering - Master AI and LLMs
|
||||
|
||||
## Setup instructions for Windows
|
||||
|
||||
**These are the original instructions for the original version of the videos from before October 2025. For the new version, see [SETUP-new.md](SETUP-new.md).**
|
||||
|
||||
Welcome, PC people!
|
||||
|
||||
I should confess up-front: setting up a powerful environment to work at the forefront of AI is not as simple as I'd like. For most people these instructions will go great; but in some cases, for whatever reason, you'll hit a problem. Please don't hesitate to reach out - I am here to get you up and running quickly. There's nothing worse than feeling _stuck_. Message me, email me or LinkedIn message me and I will unstick you quickly!
|
||||
|
||||
Email: ed@edwarddonner.com
|
||||
LinkedIn: https://www.linkedin.com/in/eddonner/
|
||||
|
||||
I use a platform called Anaconda to set up your environment. It's a powerful tool that builds a complete science environment. Anaconda ensures that you're working with the right version of Python and all your packages are compatible with mine, even if our systems are completely different. It takes more time to set up, and it uses more hard drive space (5+ GB) but it's very reliable once its working.
|
||||
|
||||
Having said that: if you have any problems with Anaconda, I've provided an alternative approach. It's faster and simpler and should have you running quickly, with less of a guarantee around compatibility.
|
||||
|
||||
If you are relatively new to using the Command Prompt, here is an excellent [guide](https://chatgpt.com/share/67b0acea-ba38-8012-9c34-7a2541052665) with instructions and exercises. I'd suggest you work through this first to build some confidence.
|
||||
|
||||
## HEAD'S UP - "GOTCHA" ISSUES ON A PC: The following 4 Windows issues will need your attention, particularly #3 and #4
|
||||
|
||||
Please do take a look at these issues. Issue #3 (Windows 260 character limit) will cause an issue with an "Archive Error" installing pytorch if unaddressed. Issue #4 will cause an installation issue.
|
||||
|
||||
There are 4 common gotchas to developing on Windows to be aware of:
|
||||
|
||||
1. Permissions. Please take a look at this [tutorial](https://chatgpt.com/share/67b0ae58-d1a8-8012-82ca-74762b0408b0) on permissions on Windows
|
||||
2. Anti-virus, Firewall, VPN. These can interfere with installations and network access; try temporarily disabling them as needed
|
||||
3. The evil Windows 260 character limit to filenames - here is a full [explanation and fix](https://chatgpt.com/share/67b0afb9-1b60-8012-a9f7-f968a5a910c7)!
|
||||
4. If you've not worked with Data Science packages on your computer before, you might need to install Microsoft Build Tools. Here are [instructions](https://chatgpt.com/share/67b0b762-327c-8012-b809-b4ec3b9e7be0). A student also mentioned that [these instructions](https://github.com/bycloudai/InstallVSBuildToolsWindows) might be helpful for people on Windows 11.
|
||||
|
||||
### Part 1: Clone the Repo
|
||||
|
||||
This gets you a local copy of the code on your box.
|
||||
|
||||
1. **Install Git** (if not already installed):
|
||||
|
||||
- Download Git from https://git-scm.com/download/win
|
||||
- Run the installer and follow the prompts, using default options (press OK lots of times!).
|
||||
- After the installation, you may need to open a new Powershell window to use it (or you might even need to restart)
|
||||
|
||||
2. **Open Command Prompt:**
|
||||
|
||||
- Press Win + R, type `cmd`, and press Enter
|
||||
|
||||
3. **Navigate to your projects folder:**
|
||||
|
||||
If you have a specific folder for projects, navigate to it using the cd command. For example:
|
||||
`cd C:\Users\YourUsername\Documents\Projects`
|
||||
Replacing YourUsername with your actual Windows user
|
||||
|
||||
If you don't have a projects folder, you can create one:
|
||||
```
|
||||
mkdir C:\Users\YourUsername\Documents\Projects
|
||||
cd C:\Users\YourUsername\Documents\Projects
|
||||
```
|
||||
|
||||
4. **Clone the repository:**
|
||||
|
||||
Enter this in the command prompt in the Projects folder:
|
||||
|
||||
`git clone https://github.com/ed-donner/llm_engineering.git`
|
||||
|
||||
This creates a new directory `llm_engineering` within your Projects folder and downloads the code for the class. Do `cd llm_engineering` to go into it. This `llm_engineering` directory is known as the "project root directory".
|
||||
|
||||
### Part 2: Install Anaconda environment
|
||||
|
||||
If this Part 2 gives you any problems, there is an alternative Part 2B below that can be used instead.
|
||||
|
||||
1. **Install Anaconda:**
|
||||
|
||||
- Download Anaconda from https://docs.anaconda.com/anaconda/install/windows/
|
||||
- Run the installer and follow the prompts. Note that it takes up several GB and take a while to install, but it will be a powerful platform for you to use in the future.
|
||||
|
||||
2. **Set up the environment:**
|
||||
|
||||
- Open **Anaconda Prompt** (search for it in the Start menu)
|
||||
- Navigate to the "project root directory" by entering something like `cd C:\Users\YourUsername\Documents\Projects\llm_engineering` using the actual path to your llm_engineering project root directory. Do a `dir` and check you can see subdirectories for each week of the course.
|
||||
- Create the environment: `conda env create -f environment.yml`
|
||||
- **If you get an ArchiveError issue, then this is caused by the Windows 260 character limit - see gotcha number 3 at the top**
|
||||
- Wait for a few minutes for all packages to be installed - in some cases, this can literally take 30 minutes if you've not used Anaconda before, and even longer depending on your internet connection. Important stuff is happening! If this runs for more than 1 hour 15 mins, or gives you other problems, please go to Part 2B instead.
|
||||
- You have now built an isolated, dedicated AI environment for engineering LLMs, running vector datastores, and so much more! You now need to **activate** it using this command: `conda activate llms`
|
||||
|
||||
You should see `(llms)` in your prompt, which indicates you've activated your new environment.
|
||||
|
||||
3. **Start Jupyter Lab:**
|
||||
|
||||
- In the Anaconda Prompt, from within the `llm_engineering` folder, type: `jupyter lab`
|
||||
|
||||
...and Jupyter Lab should open up in a browser. If you've not seen Jupyter Lab before, I'll explain it in a moment! Now close the jupyter lab browser tab, and close the Anaconda prompt, and move on to Part 3.
|
||||
|
||||
### Part 2B - Alternative to Part 2 if Anaconda gives you trouble
|
||||
|
||||
1. **Open Command Prompt**
|
||||
|
||||
Press Win + R, type `cmd`, and press Enter
|
||||
|
||||
Run `python --version` to find out which python you're on.
|
||||
Ideally you'd be using a version of Python 3.11, so we're completely in sync.
|
||||
I believe Python 3.12 works also, but (as of June 2025) Python 3.13 does **not** yet work as several Data Science dependencies are not yet ready for Python 3.13.
|
||||
If you need to install Python or install another version, you can download it here:
|
||||
https://www.python.org/downloads/
|
||||
|
||||
2. Navigate to the "project root directory" by entering something like `cd C:\Users\YourUsername\Documents\Projects\llm_engineering` using the actual path to your llm_engineering project root directory. Do a `dir` and check you can see subdirectories for each week of the course.
|
||||
|
||||
Then, create a new virtual environment with this command:
|
||||
`python -m venv llms`
|
||||
|
||||
3. Activate the virtual environment with
|
||||
`llms\Scripts\activate`
|
||||
You should see (llms) in your command prompt, which is your sign that things are going well.
|
||||
|
||||
4. Run `python -m pip install --upgrade pip` followed by `pip install -r requirements.txt`
|
||||
This may take a few minutes to install.
|
||||
If you see an error like this:
|
||||
|
||||
> Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": [https://visualstudio.microsoft.com/visual-cpp-build-tools/](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
||||
|
||||
Then please follow the link and install Microsoft C++ Build Tools. A student also mentioned that [these instructions](https://github.com/bycloudai/InstallVSBuildToolsWindows) might be helpful for people on Windows 11.
|
||||
|
||||
In the very unlikely event that this step doesn't go well, you should try the bullet-proof (but slower) version:
|
||||
`pip install --retries 5 --timeout 15 --no-cache-dir --force-reinstall -r requirements.txt`
|
||||
|
||||
6. **Start Jupyter Lab:**
|
||||
|
||||
From within the `llm_engineering` folder, type: `jupyter lab`
|
||||
...and Jupyter Lab should open up, ready for you to get started. Open the `week1` folder and double click on `day1.ipynb`. Success! Now close down jupyter lab and move on to Part 3.
|
||||
|
||||
If there are any problems, contact me!
|
||||
|
||||
### Part 3 - OpenAI key (OPTIONAL but recommended)
|
||||
|
||||
Particularly during weeks 1 and 2 of the course, you'll be writing code to call the APIs of Frontier models (models at the forefront of AI).
|
||||
|
||||
For week 1, you'll only need OpenAI, and you can add the others if you wish later on.
|
||||
|
||||
1. Create an OpenAI account if you don't have one by visiting:
|
||||
https://platform.openai.com/
|
||||
|
||||
2. OpenAI asks for a minimum credit to use the API. For me in the US, it's \$5. The API calls will spend against this \$5. On this course, we'll only use a small portion of this. I do recommend you make the investment as you'll be able to put it to excellent use. But if you'd prefer not to pay for the API, I give you an alternative in the course using Ollama.
|
||||
|
||||
You can add your credit balance to OpenAI at Settings > Billing:
|
||||
https://platform.openai.com/settings/organization/billing/overview
|
||||
|
||||
I recommend you disable the automatic recharge!
|
||||
|
||||
3. Create your API key
|
||||
|
||||
The webpage where you set up your OpenAI key is at https://platform.openai.com/api-keys - press the green 'Create new secret key' button and press 'Create secret key'. Keep a record of the API key somewhere private; you won't be able to retrieve it from the OpenAI screens in the future. It should start `sk-proj-`.
|
||||
|
||||
In week 2 we will also set up keys for Anthropic and Google, which you can do here when we get there.
|
||||
- Claude API at https://console.anthropic.com/ from Anthropic
|
||||
- Gemini API at https://ai.google.dev/gemini-api from Google
|
||||
|
||||
Later in the course you'll be using the fabulous HuggingFace platform; an account is available for free at https://huggingface.co - you can create an API token from the Avatar menu >> Settings >> Access Tokens.
|
||||
|
||||
And in Week 6/7 you'll be using the terrific Weights & Biases at https://wandb.ai to watch over your training batches. Accounts are also free, and you can set up a token in a similar way.
|
||||
|
||||
### PART 4 - .env file
|
||||
|
||||
When you have these keys, please create a new file called `.env` in your project root directory. The filename needs to be exactly the four characters ".env" rather than "my-keys.env" or ".env.txt". Here's how to do it:
|
||||
|
||||
1. Open the Notepad (Windows + R to open the Run box, enter `notepad`)
|
||||
|
||||
2. In the Notepad, type this, replacing xxxx with your API key (starting `sk-proj-`).
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=xxxx
|
||||
```
|
||||
|
||||
If you have other keys, you can add them too, or come back to this in future weeks:
|
||||
```
|
||||
GOOGLE_API_KEY=xxxx
|
||||
ANTHROPIC_API_KEY=xxxx
|
||||
DEEPSEEK_API_KEY=xxxx
|
||||
HF_TOKEN=xxxx
|
||||
```
|
||||
|
||||
Double check there are no spaces before or after the `=` sign, and no spaces at the end of the key.
|
||||
|
||||
3. Go to File > Save As. In the "Save as type" dropdown, select All Files. In the "File name" field, type exactly **.env** as the filename. Choose to save this in the project root directory (the folder called `llm_engineering`) and click Save.
|
||||
|
||||
4. Navigate to the folder where you saved the file in Explorer and ensure it was saved as ".env" not ".env.txt" - if necessary rename it to ".env" - you might need to ensure that "Show file extensions" is set to "On" so that you see the file extensions. Message or email me if that doesn't make sense!
|
||||
|
||||
This file won't appear in Jupyter Lab because jupyter hides files starting with a dot. This file is listed in the `.gitignore` file, so it won't get checked in and your keys stay safe.
|
||||
|
||||
### Part 5 - Showtime!!
|
||||
|
||||
- Open **Anaconda Prompt** (search for it in the Start menu) if you used Anaconda, otherwise open a Powershell if you used the alternative approach in Part 2B
|
||||
|
||||
- Navigate to the "project root directory" by entering something like `cd C:\Users\YourUsername\Documents\Projects\llm_engineering` using the actual path to your llm_engineering project root directory. Do a `dir` and check you can see subdirectories for each week of the course.
|
||||
|
||||
- Activate your environment with `conda activate llms` if you used Anaconda or `llms\Scripts\activate` if you used the alternative approach in Part 2B
|
||||
|
||||
- You should see (llms) in your prompt which is your sign that all is well. And now, type: `jupyter lab` and Jupyter Lab should open up, ready for you to get started. Open the `week1` folder and double click on `day1.ipynb`.
|
||||
|
||||
And you're off to the races!
|
||||
|
||||
Note that any time you start jupyter lab in the future, you'll need to follow these Part 5 instructions to start it from within the `llm_engineering` directory with the `llms` environment activated.
|
||||
|
||||
For those new to Jupyter Lab / Jupyter Notebook, it's a delightful Data Science environment where you can simply hit shift+return in any cell to run it; start at the top and work your way down! There's a notebook in the week1 folder with a [Guide to Jupyter Lab](week1/Guide%20to%20Jupyter.ipynb), and an [Intermediate Python](week1/Intermediate%20Python.ipynb) tutorial, if that would be helpful. When we move to Google Colab in Week 3, you'll experience the same interface for Python runtimes in the cloud.
|
||||
|
||||
If you have any problems, I've included a notebook in week1 called [troubleshooting.ipynb](week1/troubleshooting.ipynb) to figure it out.
|
||||
|
||||
Please do message me or email me at ed@edwarddonner.com if this doesn't work or if I can help with anything. I can't wait to hear how you get on.
|
||||
216
setup/SETUP-linux.md
Normal file
216
setup/SETUP-linux.md
Normal file
@@ -0,0 +1,216 @@
|
||||
# LLM Engineering - Master AI and LLMs
|
||||
|
||||
## Original Setup instructions for Linux
|
||||
|
||||
**These are the original instructions for the original version of the videos from before October 2025. For the new version, see [SETUP-new.md](SETUP-new.md).**
|
||||
|
||||
Welcome, Linux people!
|
||||
|
||||
I should reveal that I had ChatGPT make this document based on the Mac instructions, but then I went through and checked and tweaked some sections. If any of these instructions don't work for your distro, please do reach out and let me know - we'll figure it out, then I'll update the instructions for the future.
|
||||
|
||||
___
|
||||
|
||||
Setting up a powerful environment to work at the forefront of AI requires some effort, but these instructions should guide you smoothly. If you encounter any issues, don't hesitate to reach out to me. I'm here to ensure you get set up without hassle.
|
||||
|
||||
Email: ed@edwarddonner.com
|
||||
LinkedIn: https://www.linkedin.com/in/eddonner/
|
||||
|
||||
For this setup, we'll use Anaconda to create a reliable environment for your AI work. Alternatively, I've provided a lighter option if you prefer to avoid Anaconda. Let's get started!
|
||||
|
||||
### Part 1: Clone the Repo
|
||||
|
||||
This gets you a local copy of the code on your machine.
|
||||
|
||||
1. **Install Git** if not already installed:
|
||||
|
||||
- Open your terminal.
|
||||
- Run `git --version`. If Git isn't installed, follow the instructions for your distribution:
|
||||
- Debian/Ubuntu: `sudo apt update && sudo apt install git`
|
||||
- Fedora: `sudo dnf install git`
|
||||
- Arch: `sudo pacman -S git`
|
||||
|
||||
2. **Navigate to your projects folder:**
|
||||
|
||||
If you have a specific folder for projects, navigate to it using the `cd` command. For example:
|
||||
`cd ~/Projects`
|
||||
|
||||
If you don't have a projects folder, you can create one:
|
||||
```
|
||||
mkdir ~/Projects
|
||||
cd ~/Projects
|
||||
```
|
||||
|
||||
3. **Clone the repository:**
|
||||
|
||||
Run the following command in your terminal:
|
||||
`git clone https://github.com/ed-donner/llm_engineering.git`
|
||||
|
||||
This creates a new directory `llm_engineering` within your Projects folder and downloads the course code. Use `cd llm_engineering` to enter the directory. This is your "project root directory."
|
||||
|
||||
### Part 2: Install Anaconda environment
|
||||
|
||||
If this Part 2 gives you any trouble, refer to the alternative Part 2B below.
|
||||
|
||||
1. **Install Anaconda:**
|
||||
|
||||
- Download the Linux installer from https://www.anaconda.com/download.
|
||||
- Open a terminal and navigate to the folder containing the downloaded `.sh` file.
|
||||
- Run the installer: `bash Anaconda3*.sh` and follow the prompts. Note: This requires about 5+ GB of disk space.
|
||||
|
||||
2. **Set up the environment:**
|
||||
|
||||
- Open a terminal and navigate to the "project root directory" using:
|
||||
`cd ~/Projects/llm_engineering` (adjust the path as necessary).
|
||||
- Run `ls` to confirm the presence of subdirectories for each week of the course.
|
||||
- Create the environment: `conda env create -f environment.yml`
|
||||
|
||||
This may take several minutes (even up to an hour for new Anaconda users). If it takes longer or errors occur, proceed to Part 2B.
|
||||
|
||||
- Activate the environment: `conda activate llms`.
|
||||
|
||||
You should see `(llms)` in your prompt, indicating successful activation.
|
||||
|
||||
In some distributions this may be required so that the llms environment is visible in jupyter lab:
|
||||
|
||||
`conda install ipykernel`
|
||||
`python -m ipykernel install --user --name=llmenv`
|
||||
|
||||
3. **Start Jupyter Lab:**
|
||||
|
||||
From the `llm_engineering` folder, run: `jupyter lab`.
|
||||
|
||||
Jupyter Lab should open in your browser. Close it after confirming it works, and proceed to Part 3.
|
||||
|
||||
### Part 2B - Alternative to Part 2 if Anaconda gives you trouble
|
||||
|
||||
1. **Install Python 3.11 (if not already installed):**
|
||||
|
||||
- Debian/Ubuntu: `sudo apt update && sudo apt install python3.11`
|
||||
- Fedora: `sudo dnf install python3.11`
|
||||
- Arch: `sudo pacman -S python`
|
||||
|
||||
2. **Navigate to the project root directory:**
|
||||
|
||||
Use `cd ~/Projects/llm_engineering` and verify the folder contents with `ls`.
|
||||
|
||||
3. **Create a virtual environment:**
|
||||
|
||||
Run: `python3.11 -m venv llms`
|
||||
|
||||
4. **Activate the virtual environment:**
|
||||
|
||||
Use: `source llms/bin/activate`
|
||||
|
||||
Your prompt should now display `(llms)`, indicating the environment is active.
|
||||
|
||||
5. **Install required packages:**
|
||||
|
||||
Run: `python -m pip install --upgrade pip` followed by `pip install -r requirements.txt`.
|
||||
|
||||
If issues occur, try the fallback:
|
||||
`pip install --retries 5 --timeout 15 --no-cache-dir --force-reinstall -r requirements.txt`
|
||||
|
||||
###### Arch users:
|
||||
|
||||
Some updates break dependencies. Most notably, numpy, scipy and gensim. To troubleshoot this, you can try many commands:
|
||||
|
||||
`sudo pacman -S python-numpy python-pandas python-scipy` This is not recommended, as pacman has no integration with pip (as far as I know)
|
||||
|
||||
Another possible solution if having build conflicts, is to update:
|
||||
|
||||
`sudo pacman -S gcc gcc-fortran python-setuptools python-wheel`
|
||||
|
||||
*Note:* gensim is broken if you have an updated version of scipy. You can either pin scipy to an older version, or
|
||||
erase gensim from the requirements.txt for the moment. (See: https://aur.archlinux.org/packages/python-gensim)
|
||||
|
||||
Lastly, so that the kernel is visible after step (6) in jupyter lab :
|
||||
`python -m ipykernel install --user --name=llmenv`
|
||||
`ipython kernel install --user --name=llmenv`
|
||||
|
||||
|
||||
6. **Start Jupyter Lab:**
|
||||
|
||||
From the `llm_engineering` folder, run: `jupyter lab`.
|
||||
|
||||
|
||||
### Part 3 - OpenAI key (OPTIONAL but recommended)
|
||||
|
||||
Particularly during weeks 1 and 2 of the course, you'll be writing code to call the APIs of Frontier models (models at the forefront of AI).
|
||||
|
||||
For week 1, you'll only need OpenAI, and you can add the others if you wish later on.
|
||||
|
||||
1. Create an OpenAI account if you don't have one by visiting:
|
||||
https://platform.openai.com/
|
||||
|
||||
2. OpenAI asks for a minimum credit to use the API. For me in the US, it's \$5. The API calls will spend against this \$5. On this course, we'll only use a small portion of this. I do recommend you make the investment as you'll be able to put it to excellent use. But if you'd prefer not to pay for the API, I give you an alternative in the course using Ollama.
|
||||
|
||||
You can add your credit balance to OpenAI at Settings > Billing:
|
||||
https://platform.openai.com/settings/organization/billing/overview
|
||||
|
||||
I recommend you disable the automatic recharge!
|
||||
|
||||
3. Create your API key
|
||||
|
||||
The webpage where you set up your OpenAI key is at https://platform.openai.com/api-keys - press the green 'Create new secret key' button and press 'Create secret key'. Keep a record of the API key somewhere private; you won't be able to retrieve it from the OpenAI screens in the future. It should start `sk-proj-`.
|
||||
|
||||
In week 2 we will also set up keys for Anthropic and Google, which you can do here when we get there.
|
||||
- Claude API at https://console.anthropic.com/ from Anthropic
|
||||
- Gemini API at https://ai.google.dev/gemini-api from Google
|
||||
|
||||
Later in the course you'll be using the fabulous HuggingFace platform; an account is available for free at https://huggingface.co - you can create an API token from the Avatar menu >> Settings >> Access Tokens.
|
||||
|
||||
And in Week 6/7 you'll be using the terrific Weights & Biases at https://wandb.ai to watch over your training batches. Accounts are also free, and you can set up a token in a similar way.
|
||||
|
||||
### PART 4 - .env file
|
||||
|
||||
When you have these keys, please create a new file called `.env` in your project root directory. The filename needs to be exactly the four characters ".env" rather than "my-keys.env" or ".env.txt". Here's how to do it:
|
||||
|
||||
1. Open Terminal (Applications > Utilities > Terminal)
|
||||
|
||||
2. Navigate to the "project root directory" using `cd ~/Documents/Projects/llm_engineering` (replace this path with the actual path to the llm_engineering directory, your locally cloned version of the repo).
|
||||
|
||||
3. Create the .env file with
|
||||
|
||||
nano .env
|
||||
|
||||
4. Then type your API keys into nano, replacing xxxx with your API key (starting `sk-proj-`).
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=xxxx
|
||||
```
|
||||
|
||||
If you have other keys, you can add them too, or come back to this in future weeks:
|
||||
```
|
||||
GOOGLE_API_KEY=xxxx
|
||||
ANTHROPIC_API_KEY=xxxx
|
||||
DEEPSEEK_API_KEY=xxxx
|
||||
HF_TOKEN=xxxx
|
||||
```
|
||||
|
||||
5. Save the file:
|
||||
|
||||
Control + O
|
||||
Enter (to confirm save the file)
|
||||
Control + X to exit the editor
|
||||
|
||||
6. Use this command to list files in your project root directory:
|
||||
|
||||
`ls -a`
|
||||
|
||||
And confirm that the `.env` file is there.
|
||||
|
||||
This file won't appear in Jupyter Lab because jupyter hides files starting with a dot. This file is listed in the `.gitignore` file, so it won't get checked in and your keys stay safe.
|
||||
|
||||
### Part 5 - Showtime!!
|
||||
|
||||
1. Open a terminal.
|
||||
2. Navigate to the "project root directory" using:
|
||||
`cd ~/Projects/llm_engineering`.
|
||||
3. Activate your environment:
|
||||
- If you used Anaconda: `conda activate llms`
|
||||
- If you used the alternative: `source llms/bin/activate`
|
||||
|
||||
You should see `(llms)` in your prompt. Run: `jupyter lab` to get started.
|
||||
|
||||
Enjoy your journey into mastering AI and LLMs!
|
||||
|
||||
198
setup/SETUP-mac.md
Normal file
198
setup/SETUP-mac.md
Normal file
@@ -0,0 +1,198 @@
|
||||
# LLM Engineering - Master AI and LLMs
|
||||
|
||||
## Original Setup instructions for Mac
|
||||
|
||||
**These are the original instructions for the original version of the videos from before October 2025. For the new version, see [SETUP-new.md](SETUP-new.md).**
|
||||
|
||||
Welcome, Mac people!
|
||||
|
||||
I should confess up-front: setting up a powerful environment to work at the forefront of AI is not as simple as I'd like. For most people these instructions will go great; but in some cases, for whatever reason, you'll hit a problem. Please don't hesitate to reach out - I am here to get you up and running quickly. There's nothing worse than feeling _stuck_. Message me, email me or LinkedIn message me and I will unstick you quickly!
|
||||
|
||||
Email: ed@edwarddonner.com
|
||||
LinkedIn: https://www.linkedin.com/in/eddonner/
|
||||
|
||||
I use a platform called Anaconda to set up your environment. It's a powerful tool that builds a complete science environment. Anaconda ensures that you're working with the right version of Python and all your packages are compatible with mine, even if our systems are completely different. It takes more time to set up, and it uses more hard drive space (5+ GB) but it's very reliable once its working.
|
||||
|
||||
Having said that: if you have any problems with Anaconda, I've provided an alternative approach. It's faster and simpler and should have you running quickly, with less of a guarantee around compatibility.
|
||||
|
||||
### Before we begin
|
||||
|
||||
If you're less familiar with using the Terminal, please review this excellent [guide](https://chatgpt.com/canvas/shared/67b0b10c93a081918210723867525d2b) for some details and exercises.
|
||||
|
||||
If you're new to developing on your Mac, you may need to install XCode developer tools. Here are [instructions](https://chatgpt.com/share/67b0b8d7-8eec-8012-9a37-6973b9db11f5).
|
||||
|
||||
One "gotcha" to keep in mind: if you run anti-virus software, VPN or a Firewall, it might interfere with installations or network access. Please temporarily disable if you have problems.
|
||||
|
||||
### Part 1: Clone the Repo
|
||||
|
||||
This gets you a local copy of the code on your box.
|
||||
|
||||
1. **Install Git** if not already installed (it will be in most cases)
|
||||
|
||||
- Open Terminal (Applications > Utilities > Terminal)
|
||||
- Type `git --version` If not installed, you'll be prompted to install it
|
||||
- After the installation, you may need to open a new Terminal window to use it (or you might even need to restart)
|
||||
|
||||
2. **Navigate to your projects folder:**
|
||||
|
||||
If you have a specific folder for projects, navigate to it using the cd command. For example:
|
||||
`cd ~/Documents/Projects`
|
||||
|
||||
If you don't have a projects folder, you can create one:
|
||||
```
|
||||
mkdir ~/Documents/Projects
|
||||
cd ~/Documents/Projects
|
||||
```
|
||||
|
||||
3. **Clone the repository:**
|
||||
|
||||
Enter this in the terminal in the Projects folder:
|
||||
|
||||
`git clone https://github.com/ed-donner/llm_engineering.git`
|
||||
|
||||
This creates a new directory `llm_engineering` within your Projects folder and downloads the code for the class. Do `cd llm_engineering` to go into it. This `llm_engineering` directory is known as the "project root directory".
|
||||
|
||||
### Part 2: Install Anaconda environment
|
||||
|
||||
If this Part 2 gives you any problems, there is an alternative Part 2B below that can be used instead.
|
||||
|
||||
1. **Install Anaconda:**
|
||||
|
||||
- Download Anaconda from https://docs.anaconda.com/anaconda/install/mac-os/
|
||||
- Double-click the downloaded file and follow the installation prompts. Note that it takes up several GB and take a while to install, but it will be a powerful platform for you to use in the future.
|
||||
- After installing, you'll need to open a fresh, new Terminal to be able to use it (and you might even need to restart).
|
||||
|
||||
2. **Set up the environment:**
|
||||
|
||||
- Open a **new** Terminal (Applications > Utilities > Terminal)
|
||||
- Navigate to the "project root directory" using `cd ~/Documents/Projects/llm_engineering` (replace this path as needed with the actual path to the llm_engineering directory, your locally cloned version of the repo). Do `ls` and check you can see subdirectories for each week of the course.
|
||||
- Create the environment: `conda env create -f environment.yml`
|
||||
- Wait for a few minutes for all packages to be installed - in some cases, this can literally take 20-30 minutes if you've not used Anaconda before, and even longer depending on your internet connection. Important stuff is happening! If this runs for more than 1 hour 15 mins, or gives you other problems, please go to Part 2B instead.
|
||||
- You have now built an isolated, dedicated AI environment for engineering LLMs, running vector datastores, and so much more! You now need to **activate** it using this command: `conda activate llms`
|
||||
|
||||
You should see `(llms)` in your prompt, which indicates you've activated your new environment.
|
||||
|
||||
3. **Start Jupyter Lab:**
|
||||
|
||||
- In the Terminal window, from within the `llm_engineering` folder, type: `jupyter lab`
|
||||
|
||||
...and Jupyter Lab should open up in a browser. If you've not seen Jupyter Lab before, I'll explain it in a moment! Now close the jupyter lab browser tab, and close the Terminal, and move on to Part 3.
|
||||
|
||||
### Part 2B - Alternative to Part 2 if Anaconda gives you trouble
|
||||
|
||||
1. **Open a new Terminal** (Applications > Utilities > Terminal)
|
||||
|
||||
Run `python --version` to find out which python you're on.
|
||||
Ideally you'd be using a version of Python 3.11, so we're completely in sync.
|
||||
I believe Python 3.12 works also, but (as of Feb 2025) Python 3.13 does **not** yet work as several Data Science dependencies are not yet ready for Python 3.13.
|
||||
If you need to install Python or install another version, you can download it here:
|
||||
https://www.python.org/downloads/
|
||||
|
||||
2. Navigate to the "project root directory" using `cd ~/Documents/Projects/llm_engineering` (replace this path with the actual path to the llm_engineering directory, your locally cloned version of the repo). Do `ls` and check you can see subdirectories for each week of the course.
|
||||
|
||||
Then, create a new virtual environment with this command:
|
||||
`python -m venv llms`
|
||||
|
||||
3. Activate the virtual environment with
|
||||
`source llms/bin/activate`
|
||||
You should see (llms) in your command prompt, which is your sign that things are going well.
|
||||
|
||||
4. Run `python -m pip install --upgrade pip` followed by `pip install -r requirements.txt`
|
||||
This may take a few minutes to install.
|
||||
In the very unlikely event that this doesn't go well, you should try the bullet-proof (but slower) version:
|
||||
`pip install --retries 5 --timeout 15 --no-cache-dir --force-reinstall -r requirements.txt`
|
||||
|
||||
5. **Start Jupyter Lab:**
|
||||
|
||||
From within the `llm_engineering` folder, type: `jupyter lab`
|
||||
...and Jupyter Lab should open up, ready for you to get started. Open the `week1` folder and double click on `day1.ipynb`. Success! Now close down jupyter lab and move on to Part 3.
|
||||
|
||||
If there are any problems, contact me!
|
||||
|
||||
### Part 3 - OpenAI key (OPTIONAL but recommended)
|
||||
|
||||
Particularly during weeks 1 and 2 of the course, you'll be writing code to call the APIs of Frontier models (models at the forefront of AI).
|
||||
|
||||
For week 1, you'll only need OpenAI, and you can add the others if you wish later on.
|
||||
|
||||
1. Create an OpenAI account if you don't have one by visiting:
|
||||
https://platform.openai.com/
|
||||
|
||||
2. OpenAI asks for a minimum credit to use the API. For me in the US, it's \$5. The API calls will spend against this \$5. On this course, we'll only use a small portion of this. I do recommend you make the investment as you'll be able to put it to excellent use. But if you'd prefer not to pay for the API, I give you an alternative in the course using Ollama.
|
||||
|
||||
You can add your credit balance to OpenAI at Settings > Billing:
|
||||
https://platform.openai.com/settings/organization/billing/overview
|
||||
|
||||
I recommend you disable the automatic recharge!
|
||||
|
||||
3. Create your API key
|
||||
|
||||
The webpage where you set up your OpenAI key is at https://platform.openai.com/api-keys - press the green 'Create new secret key' button and press 'Create secret key'. Keep a record of the API key somewhere private; you won't be able to retrieve it from the OpenAI screens in the future. It should start `sk-proj-`.
|
||||
|
||||
In week 2 we will also set up keys for Anthropic and Google, which you can do here when we get there.
|
||||
- Claude API at https://console.anthropic.com/ from Anthropic
|
||||
- Gemini API at https://ai.google.dev/gemini-api from Google
|
||||
|
||||
Later in the course you'll be using the fabulous HuggingFace platform; an account is available for free at https://huggingface.co - you can create an API token from the Avatar menu >> Settings >> Access Tokens.
|
||||
|
||||
And in Week 6/7 you'll be using the terrific Weights & Biases at https://wandb.ai to watch over your training batches. Accounts are also free, and you can set up a token in a similar way.
|
||||
|
||||
### PART 4 - .env file
|
||||
|
||||
When you have these keys, please create a new file called `.env` in your project root directory. The filename needs to be exactly the four characters ".env" rather than "my-keys.env" or ".env.txt". Here's how to do it:
|
||||
|
||||
1. Open Terminal (Applications > Utilities > Terminal)
|
||||
|
||||
2. Navigate to the "project root directory" using `cd ~/Documents/Projects/llm_engineering` (replace this path with the actual path to the llm_engineering directory, your locally cloned version of the repo).
|
||||
|
||||
3. Create the .env file with
|
||||
|
||||
nano .env
|
||||
|
||||
4. Then type your API keys into nano, replacing xxxx with your API key (starting `sk-proj-`).
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=xxxx
|
||||
```
|
||||
|
||||
If you have other keys, you can add them too, or come back to this in future weeks:
|
||||
```
|
||||
GOOGLE_API_KEY=xxxx
|
||||
ANTHROPIC_API_KEY=xxxx
|
||||
DEEPSEEK_API_KEY=xxxx
|
||||
HF_TOKEN=xxxx
|
||||
```
|
||||
|
||||
5. Save the file:
|
||||
|
||||
Control + O
|
||||
Enter (to confirm save the file)
|
||||
Control + X to exit the editor
|
||||
|
||||
6. Use this command to list files in your project root directory:
|
||||
|
||||
`ls -a`
|
||||
|
||||
And confirm that the `.env` file is there.
|
||||
|
||||
This file won't appear in Jupyter Lab because jupyter hides files starting with a dot. This file is listed in the `.gitignore` file, so it won't get checked in and your keys stay safe.
|
||||
|
||||
### Part 5 - Showtime!!
|
||||
|
||||
- Open Terminal (Applications > Utilities > Terminal)
|
||||
|
||||
- Navigate to the "project root directory" using `cd ~/Documents/Projects/llm_engineering` (replace this path with the actual path to the llm_engineering directory, your locally cloned version of the repo). Do `ls` and check you can see subdirectories for each week of the course.
|
||||
|
||||
- Activate your environment with `conda activate llms` (or `source llms/bin/activate` if you used the alternative approach in Part 2B)
|
||||
|
||||
- You should see (llms) in your prompt which is your sign that all is well. And now, type: `jupyter lab` and Jupyter Lab should open up, ready for you to get started. Open the `week1` folder and double click on `day1.ipynb`.
|
||||
|
||||
And you're off to the races!
|
||||
|
||||
Note that any time you start jupyter lab in the future, you'll need to follow these Part 5 instructions to start it from within the `llm_engineering` directory with the `llms` environment activated.
|
||||
|
||||
For those new to Jupyter Lab / Jupyter Notebook, it's a delightful Data Science environment where you can simply hit shift+return in any cell to run it; start at the top and work your way down! I've included a notebook called 'Guide to Jupyter' that shows you more features. When we move to Google Colab in Week 3, you'll experience the same interface for Python runtimes in the cloud.
|
||||
|
||||
If you have any problems, I've included a notebook in week1 called [troubleshooting.ipynb](week1/troubleshooting.ipynb) to figure it out.
|
||||
|
||||
Please do message me or email me at ed@edwarddonner.com if this doesn't work or if I can help with anything. I can't wait to hear how you get on.
|
||||
213
setup/SETUP-new.md
Normal file
213
setup/SETUP-new.md
Normal file
@@ -0,0 +1,213 @@
|
||||
# LLM Engineering - Master AI and LLMs
|
||||
|
||||
## New Setup instructions for PC, Mac and Linux
|
||||
|
||||
**These are the Setup instructions for the new version of the course as of October 2025. For the original versions (Anaconda) please see the other files in this directory for your platform.**
|
||||
|
||||
_If you're looking at this in Cursor, please right click on the filename in the Explorer on the left, and select "Open preview", to view the formatted version._
|
||||
|
||||
Welcome, LLM engineers in the making!
|
||||
|
||||
I should confess up-front: setting up a powerful environment to work at the forefront of AI is not as simple as I'd like. For most people these instructions will go great; but in some cases, for whatever reason, you'll hit a problem. Please don't hesitate to reach out - I am here to get you up and running quickly. There's nothing worse than feeling _stuck_. Message me in Udemy or email me and I will unstick you quickly!
|
||||
|
||||
Email: ed@edwarddonner.com
|
||||
LinkedIn: https://www.linkedin.com/in/eddonner/
|
||||
|
||||
## Step 0 - Before we begin - addressing the "GOTCHAS" which trip up many people:
|
||||
|
||||
Ignore this section at your peril! 80% of the questions I get about setup are solved by these very common system issues.
|
||||
|
||||
1. PC people: Permissions. Please take a look at this [tutorial](https://chatgpt.com/share/67b0ae58-d1a8-8012-82ca-74762b0408b0) on permissions on Windows. If you ever have an error that you don't have the rights / permissions / ability to run a script or install software, then read this first. ChatGPT can tell you everything you need to know about Permissions on Windows.
|
||||
|
||||
2. Anti-virus, Firewall, VPN. These can interfere with installations and network access; try temporarily disabling them as needed. Use a hotspot on your phone to prove whether it's a network issue.
|
||||
|
||||
3. PC people: The evil Windows 260 character limit to filenames - here is a full [explanation and fix](https://chatgpt.com/share/67b0afb9-1b60-8012-a9f7-f968a5a910c7)!
|
||||
|
||||
4. PC people: If you've not worked with Data Science packages on your computer before, you might need to install Microsoft Build Tools. Here are [instructions](https://chatgpt.com/share/67b0b762-327c-8012-b809-b4ec3b9e7be0). A student also mentioned that [these instructions](https://github.com/bycloudai/InstallVSBuildToolsWindows) might be helpful for people on Windows 11.
|
||||
|
||||
5. Mac people: If you're new to developing on your Mac, you may need to install XCode developer tools. Here are [instructions](https://chatgpt.com/share/67b0b8d7-8eec-8012-9a37-6973b9db11f5).
|
||||
|
||||
6. SSL and other network issues due to Corporate Security: if you ever get issues with SSL, such as an API Connection issue or any certificate issue, or an error trying to download files from Ollama (a Cloudflare error) then see Q15 [here](https://edwarddonner.com/faq)
|
||||
|
||||
## STEP 1 - installing git, projects directory, Cursor
|
||||
|
||||
This is the only section with separate steps for PC people and Mac/Linux people! Please pick your section below, then reconvene for Step 2...
|
||||
|
||||
___
|
||||
|
||||
**STEP 1 FOR PC people:**
|
||||
|
||||
1. **Install Git** (if not already installed):
|
||||
|
||||
- Open a new Powershell Prompt (start menu >> Powershell). If you ever have permissions errors, try opening the Powershell by right clicking and selecting "run as Administrator"
|
||||
- Run the command `git` and see if it responds with details of the command or an error
|
||||
- If you get an error, download Git from https://git-scm.com/download/win
|
||||
- Run the installer and follow the prompts, using default options (press OK lots of times!)
|
||||
|
||||
2. **Create projects directory as needed**
|
||||
|
||||
- Open a new Powershell prompt, as in prior step. You should be in your home directory, like `C:\Users\YourUserName`
|
||||
- Do you have a projects directory? Find out by typing `cd projects`
|
||||
- If that has an error, then create a projects directory: `mkdir projects` then `cd projects`
|
||||
- Now you should be in `C:\Users\YourUserName\projects`
|
||||
- You can locate this anywhere convenient for you, but avoid any directories that are on your OneDrive
|
||||
|
||||
3. **Do a git clone:**
|
||||
|
||||
Enter this in the command prompt in the Projects folder:
|
||||
|
||||
`git clone https://github.com/ed-donner/llm_engineering.git`
|
||||
|
||||
This creates a new directory `llm_engineering` within your projects folder and downloads the code for the class.
|
||||
Do `cd llm_engineering` to go into it. This `llm_engineering` directory is known as the "project root directory".
|
||||
|
||||
4. **Cursor** Install Cursor if needed and open the project:
|
||||
|
||||
Visit https://cursor.com
|
||||
|
||||
Click Download for Windows. Then run the installer. Accept and pick defaults for everything..
|
||||
|
||||
Then go to Start menu, enter cursor. Cursor will come up, and you might need to answer questions. Then you should see the 'new window' screen where you can click "Open Project". If not, go to File menu >> New Window. Then click "Open Project".
|
||||
|
||||
Find your llm_engineering directory within your projects directory. Double click on llm_engineering so you're looking at the contents of llm_engineering. Then click Open or Open Folder.
|
||||
|
||||
Cursor should then open up llm_engineering. You know you're in good shape if you see LLM_ENGINEERING in block caps on the top left.
|
||||
|
||||
___
|
||||
|
||||
**STEP 1 FOR MAC/LINUX PEOPLE**
|
||||
|
||||
1. **Install Git** (if not already installed):
|
||||
|
||||
Open a Terminal: on Mac, open a Finder window, go to Applications >> Utilities >> Terminal. On Linux, you people live in Terminals.. you hardly need instructions from me!
|
||||
|
||||
- Run `git --version` and you should see a git version number. If not, you should get instructions on how to install it, or follow gotcha #5 at the top of this doc.
|
||||
|
||||
2. **Create projects directory as needed**
|
||||
|
||||
- Open a new Terminal window, as in prior step. Type `pwd` to see where you are. You should be in your home directory, like `/Users/username`
|
||||
- Do you have a projects directory? Find out by typing `cd projects`
|
||||
- If that has an error, then create a projects directory: `mkdir projects` then `cd projects`
|
||||
- If you now do `pwd` you should be in `/Users/username/projects`
|
||||
- You can locate this anywhere convenient for you, but avoid any directories that are on your icloud
|
||||
|
||||
3. **Do a git clone:**
|
||||
|
||||
Enter this in the command prompt in the Projects folder:
|
||||
|
||||
`git clone https://github.com/ed-donner/llm_engineering.git`
|
||||
|
||||
This creates a new directory `llm_engineering` within your projects folder and downloads the code for the class.
|
||||
Do `cd llm_engineering` to go into it. This `llm_engineering` directory is known as the "project root directory".
|
||||
|
||||
4. **Cursor** Install Cursor if needed and open the project:
|
||||
|
||||
Visit https://cursor.com
|
||||
|
||||
Click Download for Mac OS. Or Linux. Then run the installer. Accept and pick defaults for everything..
|
||||
|
||||
Then go to Start menu, enter cursor. Cursor will come up, and you might need to answer questions. Then you should see the 'new window' screen where you can click "Open Project". If not, go to File menu >> New Window. Then click "Open Project".
|
||||
|
||||
Find your llm_engineering directory within your projects directory. Double click on llm_engineering so you're looking at the contents of llm_engineering. Then click Open.
|
||||
|
||||
Cursor should then open up llm_engineering. You know you're in good shape if you see LLM_ENGINEERING in block caps on the top left.
|
||||
|
||||
___
|
||||
|
||||
## STEP 2: Installing the fabulous **uv** then doing a `uv sync`
|
||||
|
||||
For this course, we're using uv, the blazingly fast package manager. It's really taken off in the Data Science world -- and for good reason.
|
||||
|
||||
It's fast and reliable. You're going to love it!
|
||||
|
||||
First, within Cursor, select View >> Terminal, to see a Terminal window within Cursor. Type `pwd` to check you're in the project root directory.
|
||||
|
||||
Now type `uv --version` to see if uv is installed. If you get a version number, then terrific! But if you get an error, then follow the instructions here to install uv - I recommend using the Standalone Installer approach at the very top, but you can use any approach. Run commands in the Cursor installer. If one approach doesn't work for you, then try another.
|
||||
|
||||
https://docs.astral.sh/uv/getting-started/installation/
|
||||
|
||||
Once you've installed uv, you need to open a new terminal window in Cursor (the plus sign or Ctrl+shift+backtick) for `uv --version` to work. Please check!
|
||||
|
||||
Mac people: if you hit a problem with not having permissions to edit your profile files, please see Q14 [here](https://edwarddonner.com/faq) for the fix to this common Mac configuration issue.
|
||||
|
||||
### Now that it's installed:
|
||||
|
||||
Run `uv self update` to make sure you're on the latest version of uv.
|
||||
|
||||
One thing to watch for: if you've used Anaconda before, make sure that your Anaconda environment is deactivated
|
||||
`conda deactivate`
|
||||
And if you still have any problems with conda and python versions, it's possible that you will need to run this too:
|
||||
`conda config --set auto_activate_base false`
|
||||
|
||||
And now simply run:
|
||||
`uv sync`
|
||||
And marvel at the speed and reliability! If necessary, uv should install python 3.12, and then it should install all the packages.
|
||||
If you get an error about "invalid certificate" while running `uv sync`, then please check Gotcha 6 above, and try this instead:
|
||||
`uv --native-tls sync`
|
||||
And also try this instead:
|
||||
`uv --allow-insecure-host github.com sync`
|
||||
|
||||
And you now have a full spec environment!!
|
||||
|
||||
___
|
||||
|
||||
## STEP 3 - OPTIONAL - Set up OpenAI Account
|
||||
|
||||
Alternative: see Guide 9 in the guides folder for free alternatives!
|
||||
|
||||
Go to https://platform.openai.com
|
||||
|
||||
- Click Sign Up to create an account if you don't have one. You might need to click some buttons to create an Organization first - just put in sensible defaults. See Guide 4 in the Guides folder if you're unsure about the differences between ChatGPT and the OpenAI API.
|
||||
- Click on the Settings icon on the top right, and then Billing on the left sidebar navigation.
|
||||
- Ensure Auto-Recharge is off. As needed, "Add to Credit Balance" and pick the $5 up-front payment amount, be sure that you add a proper payment method
|
||||
- Still in Settings, select API keys in the left sidebar (near the top)
|
||||
- Press "Create new secret key" - select "Owned by you", give it any name you want, for the project select "Default project", leave Permissions at All
|
||||
- Press "Create secret key" and you should see your new key. Press Copy to copy it into your clipboard.
|
||||
|
||||
___
|
||||
|
||||
## STEP 4 - needed for any model like OpenAI or Gemini, but not needed if you only use Ollama - create (and SAVE) your .env file
|
||||
|
||||
**Be dilligent with this section!** - any mistakes with your key will be very hard to track down!! I get a huge volume of questions from students who make a mistake with one of these steps... Above all, remember to save the file after you change it.
|
||||
|
||||
1. Create your `.env` file
|
||||
|
||||
- Go back to Cursor
|
||||
- In the File Explorer on the left, right click in the blank space at the bottom of all your files, select "New File" and call your file `.env`
|
||||
- I can't stress this enough: the file needs to be called PRECISELY `.env` - those four characters, no more and no less. Not ".env.txt" and not "john.env" and not "openai.env" and not anything else! And it needs to be within the project root.
|
||||
|
||||
If you're wondering why I rant about this: I get many, many frustrated people contacting me who (despite all my appeals) have named the file something else and think it's OK. It's not OK! It needs to be called `.env` in the llm_engineering directory 😂
|
||||
|
||||
2. Populate your `.env` file and then Save it:
|
||||
|
||||
Select the file on the left. You should see an empty blank file on the right. And type this into the contents of the file in the right:
|
||||
|
||||
`OPENAI_API_KEY=`
|
||||
|
||||
And then press paste! You should now see something like this:
|
||||
|
||||
`OPENAI_API_KEY=sk-proj-lots-and-lots-of-digits`
|
||||
|
||||
But obviously with your actual key there, not the words "sk-proj-lots-and-lots-of-digits"..
|
||||
|
||||
Now be sure to SAVE the file! File >> Save or Ctrl+S (PC) or Command+S (Mac). Many people forget to Save. You need to Save the file!
|
||||
|
||||
You should see a Stop sign by the .env file - don't be concerned.. this is a good thing! See Q7 [here](https://edwarddonner.com/faq) if you want to understand why.
|
||||
|
||||
__
|
||||
|
||||
## STEP 5 - Install Cursor Extensions, Open Day 1, Set the Kernel and GO!
|
||||
|
||||
(If you are prompted in Cursor to install recommended extensions, just say yes! That is a nice shortcut for this step.)
|
||||
|
||||
- Go to view menu and select Extensions.
|
||||
- Search for "python" to bring up the Python extensions. Select the Python extension made by "ms-python" or by "anysphere" and install it if not already installed.
|
||||
- Search for "jupyter" and select the extension made by "ms-toolsai" and install it if not already installed.
|
||||
|
||||
Now go to View >> Explorer. Open the week1 folder, and click on `day1.ipynb`.
|
||||
|
||||
- See where it says "Select Kernel" near the top right? Click that.. then pick "Python Environments"
|
||||
- Pick the top option with a star that should say something like `.venv (Python 3.12.x) .venv/bin/python Recommended`
|
||||
- If this doesn't come up, please go to the troubleshooting lab in the Setup folder.
|
||||
|
||||
# CONGRATULATIONS!! You made it! The rest of the course is easy 😂
|
||||
54
setup/diagnostics.ipynb
Normal file
54
setup/diagnostics.ipynb
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "73287ed4-81e3-496a-9e47-f0e8c3770ce9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Gathering Essential Diagnostic information\n",
|
||||
"\n",
|
||||
"## Please run this next cell to gather some important data\n",
|
||||
"\n",
|
||||
"Please run the next cell; it should take a minute or so to run (mostly the network test).\n",
|
||||
"Rhen email me the output of the last cell to ed@edwarddonner.com. \n",
|
||||
"Alternatively: this will create a file called report.txt - just attach the file to your email."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ed8056e8-efa2-4b6f-a4bb-e7ceb733c517",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Run my diagnostics report to collect key information for debugging\n",
|
||||
"# Please email me the results. Either copy & paste the output, or attach the file report.txt\n",
|
||||
"\n",
|
||||
"!pip install -q requests speedtest-cli psutil setuptools\n",
|
||||
"from diagnostics import Diagnostics\n",
|
||||
"Diagnostics().run()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
419
setup/diagnostics.py
Normal file
419
setup/diagnostics.py
Normal file
@@ -0,0 +1,419 @@
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
import subprocess
|
||||
import shutil
|
||||
import time
|
||||
import ssl
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
class Diagnostics:
|
||||
|
||||
FILENAME = 'report.txt'
|
||||
|
||||
def __init__(self):
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
if os.path.exists(self.FILENAME):
|
||||
os.remove(self.FILENAME)
|
||||
|
||||
def log(self, message):
|
||||
print(message)
|
||||
with open(self.FILENAME, 'a', encoding='utf-8') as f:
|
||||
f.write(message + "\n")
|
||||
|
||||
def start(self):
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.log(f"Starting diagnostics at {now}\n")
|
||||
|
||||
def end(self):
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.log(f"\n\nCompleted diagnostics at {now}\n")
|
||||
print("\nPlease send these diagnostics to me at ed@edwarddonner.com")
|
||||
print(f"Either copy & paste the above output into an email, or attach the file {self.FILENAME} that has been created in this directory.")
|
||||
|
||||
|
||||
def _log_error(self, message):
|
||||
self.log(f"ERROR: {message}")
|
||||
self.errors.append(message)
|
||||
|
||||
def _log_warning(self, message):
|
||||
self.log(f"WARNING: {message}")
|
||||
self.warnings.append(message)
|
||||
|
||||
def run(self):
|
||||
self.start()
|
||||
self._step1_system_info()
|
||||
self._step2_check_files()
|
||||
self._step3_git_repo()
|
||||
self._step4_check_env_file()
|
||||
self._step5_anaconda_check()
|
||||
self._step6_virtualenv_check()
|
||||
self._step7_network_connectivity()
|
||||
self._step8_environment_variables()
|
||||
self._step9_additional_diagnostics()
|
||||
|
||||
if self.warnings:
|
||||
self.log("\n===== Warnings Found =====")
|
||||
self.log("The following warnings were detected. They might not prevent the program from running but could cause unexpected behavior:")
|
||||
for warning in self.warnings:
|
||||
self.log(f"- {warning}")
|
||||
|
||||
if self.errors:
|
||||
self.log("\n===== Errors Found =====")
|
||||
self.log("The following critical issues were detected. Please address them before proceeding:")
|
||||
for error in self.errors:
|
||||
self.log(f"- {error}")
|
||||
|
||||
if not self.errors and not self.warnings:
|
||||
self.log("\n✅ All diagnostics passed successfully!")
|
||||
|
||||
self.end()
|
||||
|
||||
def _step1_system_info(self):
|
||||
self.log("===== System Information =====")
|
||||
try:
|
||||
system = platform.system()
|
||||
self.log(f"Operating System: {system}")
|
||||
|
||||
if system == "Windows":
|
||||
release, version, csd, ptype = platform.win32_ver()
|
||||
self.log(f"Windows Release: {release}")
|
||||
self.log(f"Windows Version: {version}")
|
||||
elif system == "Darwin":
|
||||
release, version, machine = platform.mac_ver()
|
||||
self.log(f"MacOS Version: {release}")
|
||||
else:
|
||||
self.log(f"Platform: {platform.platform()}")
|
||||
|
||||
self.log(f"Architecture: {platform.architecture()}")
|
||||
self.log(f"Machine: {platform.machine()}")
|
||||
self.log(f"Processor: {platform.processor()}")
|
||||
|
||||
try:
|
||||
import psutil
|
||||
ram = psutil.virtual_memory()
|
||||
total_ram_gb = ram.total / (1024 ** 3)
|
||||
available_ram_gb = ram.available / (1024 ** 3)
|
||||
self.log(f"Total RAM: {total_ram_gb:.2f} GB")
|
||||
self.log(f"Available RAM: {available_ram_gb:.2f} GB")
|
||||
|
||||
if available_ram_gb < 2:
|
||||
self._log_warning(f"Low available RAM: {available_ram_gb:.2f} GB")
|
||||
except ImportError:
|
||||
self._log_warning("psutil module not found. Cannot determine RAM information.")
|
||||
|
||||
total, used, free = shutil.disk_usage(os.path.expanduser("~"))
|
||||
free_gb = free / (1024 ** 3)
|
||||
self.log(f"Free Disk Space: {free_gb:.2f} GB")
|
||||
|
||||
if free_gb < 5:
|
||||
self._log_warning(f"Low disk space: {free_gb:.2f} GB free")
|
||||
|
||||
except Exception as e:
|
||||
self._log_error(f"System information check failed: {e}")
|
||||
|
||||
def _step2_check_files(self):
|
||||
self.log("\n===== File System Information =====")
|
||||
try:
|
||||
current_dir = os.getcwd()
|
||||
self.log(f"Current Directory: {current_dir}")
|
||||
|
||||
# Check write permissions
|
||||
test_file = Path(current_dir) / ".test_write_permission"
|
||||
try:
|
||||
test_file.touch(exist_ok=True)
|
||||
test_file.unlink()
|
||||
self.log("Write permission: OK")
|
||||
except Exception as e:
|
||||
self._log_error(f"No write permission in current directory: {e}")
|
||||
|
||||
self.log("\nFiles in Current Directory:")
|
||||
try:
|
||||
for item in sorted(os.listdir(current_dir)):
|
||||
self.log(f" - {item}")
|
||||
except Exception as e:
|
||||
self._log_error(f"Cannot list directory contents: {e}")
|
||||
|
||||
except Exception as e:
|
||||
self._log_error(f"File system check failed: {e}")
|
||||
|
||||
def _step3_git_repo(self):
|
||||
self.log("\n===== Git Repository Information =====")
|
||||
try:
|
||||
result = subprocess.run(['git', 'rev-parse', '--show-toplevel'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
if result.returncode == 0:
|
||||
git_root = result.stdout.strip()
|
||||
self.log(f"Git Repository Root: {git_root}")
|
||||
|
||||
result = subprocess.run(['git', 'rev-parse', 'HEAD'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
if result.returncode == 0:
|
||||
self.log(f"Current Commit: {result.stdout.strip()}")
|
||||
else:
|
||||
self._log_warning(f"Could not get current commit: {result.stderr.strip()}")
|
||||
|
||||
result = subprocess.run(['git', 'remote', 'get-url', 'origin'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
if result.returncode == 0:
|
||||
self.log(f"Remote Origin: {result.stdout.strip()}")
|
||||
else:
|
||||
self._log_warning("No remote 'origin' configured")
|
||||
else:
|
||||
self._log_warning("Not a git repository")
|
||||
except FileNotFoundError:
|
||||
self._log_warning("Git is not installed or not in PATH")
|
||||
except Exception as e:
|
||||
self._log_error(f"Git check failed: {e}")
|
||||
|
||||
def _step4_check_env_file(self):
|
||||
self.log("\n===== Environment File Check =====")
|
||||
try:
|
||||
result = subprocess.run(['git', 'rev-parse', '--show-toplevel'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
if result.returncode == 0:
|
||||
git_root = result.stdout.strip()
|
||||
env_path = os.path.join(git_root, '.env')
|
||||
|
||||
if os.path.isfile(env_path):
|
||||
self.log(f".env file exists at: {env_path}")
|
||||
try:
|
||||
with open(env_path, 'r') as f:
|
||||
has_api_key = any(line.strip().startswith('OPENAI_API_KEY=') for line in f)
|
||||
if has_api_key:
|
||||
self.log("OPENAI_API_KEY found in .env file")
|
||||
else:
|
||||
self._log_warning("OPENAI_API_KEY not found in .env file")
|
||||
except Exception as e:
|
||||
self._log_error(f"Cannot read .env file: {e}")
|
||||
else:
|
||||
self._log_warning(".env file not found in project root")
|
||||
|
||||
# Check for additional .env files
|
||||
for root, _, files in os.walk(git_root):
|
||||
if '.env' in files and os.path.join(root, '.env') != env_path:
|
||||
self._log_warning(f"Additional .env file found at: {os.path.join(root, '.env')}")
|
||||
else:
|
||||
self._log_warning("Git root directory not found. Cannot perform .env file check.")
|
||||
except FileNotFoundError:
|
||||
self._log_warning("Git is not installed or not in PATH")
|
||||
except Exception as e:
|
||||
self._log_error(f"Environment file check failed: {e}")
|
||||
|
||||
def _step5_anaconda_check(self):
|
||||
self.log("\n===== Anaconda Environment Check =====")
|
||||
try:
|
||||
conda_prefix = os.environ.get('CONDA_PREFIX')
|
||||
if conda_prefix:
|
||||
self.log("Anaconda environment is active:")
|
||||
self.log(f"Environment Path: {conda_prefix}")
|
||||
self.log(f"Environment Name: {os.path.basename(conda_prefix)}")
|
||||
|
||||
conda_exe = os.environ.get('CONDA_EXE', 'conda')
|
||||
result = subprocess.run([conda_exe, '--version'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
if result.returncode == 0:
|
||||
self.log(f"Conda Version: {result.stdout.strip()}")
|
||||
else:
|
||||
self._log_warning("Could not determine Conda version")
|
||||
|
||||
self._check_python_packages()
|
||||
else:
|
||||
self.log("No active Anaconda environment detected")
|
||||
except Exception as e:
|
||||
self._log_error(f"Anaconda environment check failed: {e}")
|
||||
|
||||
def _step6_virtualenv_check(self):
|
||||
self.log("\n===== Virtualenv Check =====")
|
||||
try:
|
||||
virtual_env = os.environ.get('VIRTUAL_ENV')
|
||||
if virtual_env:
|
||||
self.log("Virtualenv is active:")
|
||||
self.log(f"Environment Path: {virtual_env}")
|
||||
self.log(f"Environment Name: {os.path.basename(virtual_env)}")
|
||||
|
||||
self._check_python_packages()
|
||||
else:
|
||||
self.log("No active virtualenv detected")
|
||||
|
||||
if not virtual_env and not os.environ.get('CONDA_PREFIX'):
|
||||
self._log_warning("Neither virtualenv nor Anaconda environment is active")
|
||||
except Exception as e:
|
||||
self._log_error(f"Virtualenv check failed: {e}")
|
||||
|
||||
def _check_python_packages(self):
|
||||
self.log("\nPython Environment:")
|
||||
self.log(f"Python Version: {sys.version}")
|
||||
self.log(f"Python Executable: {sys.executable}")
|
||||
|
||||
required_packages = ['openai', 'python-dotenv', 'requests', 'gradio', 'transformers']
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
installed = {pkg.key: pkg.version for pkg in pkg_resources.working_set}
|
||||
|
||||
self.log("\nRequired Package Versions:")
|
||||
for package in required_packages:
|
||||
if package in installed:
|
||||
self.log(f"{package}: {installed[package]}")
|
||||
else:
|
||||
self._log_error(f"Required package '{package}' is not installed")
|
||||
|
||||
# Check for potentially conflicting packages
|
||||
problem_pairs = [
|
||||
('openai', 'openai-python'),
|
||||
('python-dotenv', 'dotenv')
|
||||
]
|
||||
|
||||
for pkg1, pkg2 in problem_pairs:
|
||||
if pkg1 in installed and pkg2 in installed:
|
||||
self._log_warning(f"Potentially conflicting packages: {pkg1} and {pkg2}")
|
||||
except ImportError:
|
||||
self._log_error("Could not import 'pkg_resources' to check installed packages")
|
||||
except Exception as e:
|
||||
self._log_error(f"Package check failed: {e}")
|
||||
|
||||
def _step7_network_connectivity(self):
|
||||
self.log("\n===== Network Connectivity Check =====")
|
||||
try:
|
||||
self.log(f"SSL Version: {ssl.OPENSSL_VERSION}")
|
||||
|
||||
import requests
|
||||
import speedtest # Importing the speedtest-cli library
|
||||
|
||||
# Basic connectivity check
|
||||
urls = [
|
||||
'https://www.google.com',
|
||||
'https://www.cloudflare.com'
|
||||
]
|
||||
|
||||
connected = False
|
||||
for url in urls:
|
||||
try:
|
||||
start_time = time.time()
|
||||
response = requests.get(url, timeout=10)
|
||||
elapsed_time = time.time() - start_time
|
||||
response.raise_for_status()
|
||||
self.log(f"✓ Connected to {url}")
|
||||
self.log(f" Response time: {elapsed_time:.2f}s")
|
||||
|
||||
if elapsed_time > 2:
|
||||
self._log_warning(f"Slow response from {url}: {elapsed_time:.2f}s")
|
||||
connected = True
|
||||
break
|
||||
except requests.exceptions.RequestException as e:
|
||||
self._log_warning(f"Failed to connect to {url}: {e}")
|
||||
else:
|
||||
self.log("Basic connectivity OK")
|
||||
|
||||
if not connected:
|
||||
self._log_error("Failed to connect to any test URLs")
|
||||
return
|
||||
|
||||
# Bandwidth test using speedtest-cli
|
||||
self.log("\nPerforming bandwidth test using speedtest-cli...")
|
||||
try:
|
||||
st = speedtest.Speedtest()
|
||||
st.get_best_server()
|
||||
download_speed = st.download() # Bits per second
|
||||
upload_speed = st.upload() # Bits per second
|
||||
|
||||
download_mbps = download_speed / 1e6 # Convert to Mbps
|
||||
upload_mbps = upload_speed / 1e6
|
||||
|
||||
self.log(f"Download speed: {download_mbps:.2f} Mbps")
|
||||
self.log(f"Upload speed: {upload_mbps:.2f} Mbps")
|
||||
|
||||
if download_mbps < 1:
|
||||
self._log_warning("Download speed is low")
|
||||
if upload_mbps < 0.5:
|
||||
self._log_warning("Upload speed is low")
|
||||
except speedtest.ConfigRetrievalError:
|
||||
self._log_error("Failed to retrieve speedtest configuration")
|
||||
except Exception as e:
|
||||
self._log_warning(f"Bandwidth test failed: {e}")
|
||||
|
||||
except ImportError:
|
||||
self._log_error("Required packages are not installed. Please install them using 'pip install requests speedtest-cli'")
|
||||
except Exception as e:
|
||||
self._log_error(f"Network connectivity check failed: {e}")
|
||||
|
||||
|
||||
def _step8_environment_variables(self):
|
||||
self.log("\n===== Environment Variables Check =====")
|
||||
try:
|
||||
# Check Python paths
|
||||
pythonpath = os.environ.get('PYTHONPATH')
|
||||
if pythonpath:
|
||||
self.log("\nPYTHONPATH:")
|
||||
for path in pythonpath.split(os.pathsep):
|
||||
self.log(f" - {path}")
|
||||
else:
|
||||
self.log("\nPYTHONPATH is not set.")
|
||||
|
||||
self.log("\nPython sys.path:")
|
||||
for path in sys.path:
|
||||
self.log(f" - {path}")
|
||||
|
||||
# Check OPENAI_API_KEY
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
api_key = os.environ.get('OPENAI_API_KEY')
|
||||
if api_key:
|
||||
self.log("OPENAI_API_KEY is set after calling load_dotenv()")
|
||||
if not api_key.startswith('sk-proj-') or len(api_key)<12:
|
||||
self._log_warning("OPENAI_API_KEY format looks incorrect after calling load_dotenv()")
|
||||
else:
|
||||
self._log_warning("OPENAI_API_KEY environment variable is not set after calling load_dotenv()")
|
||||
except Exception as e:
|
||||
self._log_error(f"Environment variables check failed: {e}")
|
||||
|
||||
def _step9_additional_diagnostics(self):
|
||||
self.log("\n===== Additional Diagnostics =====")
|
||||
try:
|
||||
# Get the site-packages directory paths
|
||||
import site
|
||||
site_packages_paths = site.getsitepackages()
|
||||
if hasattr(site, 'getusersitepackages'):
|
||||
site_packages_paths.append(site.getusersitepackages())
|
||||
|
||||
# Function to check if a path is within site-packages
|
||||
def is_in_site_packages(path):
|
||||
return any(os.path.commonpath([path, sp]) == sp for sp in site_packages_paths)
|
||||
|
||||
# Check for potential name conflicts in the current directory and sys.path
|
||||
conflict_names = ['openai.py', 'dotenv.py']
|
||||
|
||||
# Check current directory
|
||||
current_dir = os.getcwd()
|
||||
for name in conflict_names:
|
||||
conflict_path = os.path.join(current_dir, name)
|
||||
if os.path.isfile(conflict_path):
|
||||
self._log_warning(f"Found '{name}' in the current directory, which may cause import conflicts: {conflict_path}")
|
||||
|
||||
# Check sys.path directories
|
||||
for path in sys.path:
|
||||
if not path or is_in_site_packages(path):
|
||||
continue # Skip site-packages and empty paths
|
||||
for name in conflict_names:
|
||||
conflict_file = os.path.join(path, name)
|
||||
if os.path.isfile(conflict_file):
|
||||
self._log_warning(f"Potential naming conflict: {conflict_file}")
|
||||
|
||||
# Check temp directory
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile() as tmp:
|
||||
self.log(f"Temp directory is writable: {os.path.dirname(tmp.name)}")
|
||||
except Exception as e:
|
||||
self._log_error(f"Cannot write to temp directory: {e}")
|
||||
|
||||
except Exception as e:
|
||||
self._log_error(f"Additional diagnostics failed: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
diagnostics = Diagnostics()
|
||||
diagnostics.run()
|
||||
557
setup/troubleshooting.ipynb
Normal file
557
setup/troubleshooting.ipynb
Normal file
@@ -0,0 +1,557 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2a793b1d-a0a9-404c-ada6-58937227cfce",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Oh dear!\n",
|
||||
"\n",
|
||||
"If you've got here, then you're still having problems setting up your environment. I'm so sorry! Hang in there and we should have you up and running in no time.\n",
|
||||
"\n",
|
||||
"Setting up a Data Science environment can be challenging because there's a lot going on under the hood. But we will get there.\n",
|
||||
"\n",
|
||||
"And please remember - I'm standing by to help out. Message me or email ed@edwarddonner.com and I'll get on the case. The very last cell in this notebook has some diagnostics that will help me figure out what's happening.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8ebcd34f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# If you are taking the new version of the course (using uv and Cursor, rather than Anaconda) then check this section first, otherwise jump ahead to the next section headed \"Starting with the basics\"\n",
|
||||
"\n",
|
||||
"## 1. Check Cursor extensions\n",
|
||||
"\n",
|
||||
"Just to confirm that the extensions are installed:\n",
|
||||
"- Open extensions (View >> extensions)\n",
|
||||
"- Search for python, and when the results show, click on the ms-python one, and Install it if not already installed\n",
|
||||
"- Search for jupyter, and when the results show, click on the Microsoft one, and Install it if not already installed \n",
|
||||
"Then View >> Explorer to bring back the File Explorer.\n",
|
||||
"\n",
|
||||
"## 2. Connect this Kernel:\n",
|
||||
"\n",
|
||||
"If you see the words `Select Kernel` in a button near the top right of this Window, then press the button!\n",
|
||||
"\n",
|
||||
"You should see a drop down titled \"Select kernel for..\" or you might need to pick \"Python environment\" first.\n",
|
||||
"\n",
|
||||
"Pick the one that begins `.venv python 3.12` - it should be the top choice. You might need to click \"Python Environments\" first.\n",
|
||||
"\n",
|
||||
"It should now say `.venv (Python 3.12.x)` where it used to say `Select Kernel`.\n",
|
||||
"\n",
|
||||
"After you click \"Select Kernel\", if there is no option like `.venv (Python 3.12.x)` then please do the following: \n",
|
||||
"1. On Mac: From the Cursor menu, choose Settings >> VS Code Settings (NOTE: be sure to select `VSCode Settings` not `Cursor Settings`); \n",
|
||||
"Or on Windows PC: From the File menu, choose Preferences >> VS Code Settings (NOTE: be sure to select `VSCode Settings` not `Cursor Settings`) \n",
|
||||
"2. In the Settings search bar, type \"venv\" \n",
|
||||
"3. In the field \"Path to folder with a list of Virtual Environments\" put the path to the project root, like C:\\Users\\username\\projects\\llm_engineering (on a Windows PC) or /Users/username/projects/llm_engineering (on Mac or Linux). \n",
|
||||
"And then try again.\n",
|
||||
"\n",
|
||||
"## 3. Anaconda interference and Python version horrors\n",
|
||||
"\n",
|
||||
"Having problems with missing Python versions? Have you ever used Anaconda before? It might be interferring. Quit Cursor, bring up a new command line, and make sure that your Anaconda environment is deactivated: \n",
|
||||
"`conda deactivate` \n",
|
||||
"And if you still have any problems with conda and python versions, it's possible that you will need to run this too: \n",
|
||||
"`conda config --set auto_activate_base false` \n",
|
||||
"And then start a new Terminal / Powershell. \n",
|
||||
"and then from within the agents directory, you should be able to run `uv python list` and see the Python 3.12 version. \n",
|
||||
"And this shouldn't be required, but if you want to be absolutely careful, then now: \n",
|
||||
"1. Delete the folder called '.venv' in the project root directory \n",
|
||||
"2. `uv python uninstall 3.12`\n",
|
||||
"3. `uv python install 3.12`\n",
|
||||
"4. `uv python list`\n",
|
||||
"5. `uv sync` \n",
|
||||
"And surely that is bulletproof!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "98787335-346f-4ee4-9cb7-6181b0e1b964",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Starting with the basics\n",
|
||||
"\n",
|
||||
"## Checking your internet connection\n",
|
||||
"\n",
|
||||
"First let's check that there's no VPN or Firewall or Certs problem.\n",
|
||||
"\n",
|
||||
"Click in the cell below and press Shift+Return to run it. \n",
|
||||
"If this gives you problems, then please try working through these instructions to address: \n",
|
||||
"https://chatgpt.com/share/676e6e3b-db44-8012-abaa-b3cf62c83eb3\n",
|
||||
"\n",
|
||||
"I've also heard that you might have problems if you are using a work computer that's running security software zscaler.\n",
|
||||
"\n",
|
||||
"Some advice from students in this situation with zscaler:\n",
|
||||
"\n",
|
||||
"> In the anaconda prompt, this helped sometimes, although still got failures occasionally running code in Jupyter:\n",
|
||||
"`conda config --set ssl_verify false` \n",
|
||||
"Another thing that helped was to add `verify=False` anytime where there is `request.get(..)`, so `request.get(url, headers=headers)` becomes `request.get(url, headers=headers, verify=False)`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d296f9b6-8de4-44db-b5f5-9b653dfd3d81",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import urllib.request\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" response = urllib.request.urlopen(\"https://www.google.com\", timeout=10)\n",
|
||||
" if response.status != 200:\n",
|
||||
" print(\"Unable to reach google - there may be issues with your internet / VPN / firewall?\")\n",
|
||||
" else:\n",
|
||||
" print(\"Connected to the internet and can reach Google\")\n",
|
||||
"except Exception as e:\n",
|
||||
" print(f\"Failed to connect with this error: {e}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d91da3b2-5a41-4233-9ed6-c53a7661b328",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Another mention of occasional \"gotchas\" for PC people\n",
|
||||
"\n",
|
||||
"There are 4 snafus on Windows to be aware of: \n",
|
||||
"1. Permissions. Please take a look at this [tutorial](https://chatgpt.com/share/67b0ae58-d1a8-8012-82ca-74762b0408b0) on permissions on Windows\n",
|
||||
"2. Anti-virus, Firewall, VPN. These can interfere with installations and network access; try temporarily disabling them as needed\n",
|
||||
"3. The evil Windows 260 character limit to filenames - here is a full [explanation and fix](https://chatgpt.com/share/67b0afb9-1b60-8012-a9f7-f968a5a910c7)!\n",
|
||||
"4. If you've not worked with Data Science packages on your computer before, you might need to install Microsoft Build Tools. Here are [instructions](https://chatgpt.com/share/67b0b762-327c-8012-b809-b4ec3b9e7be0). A student also mentioned that [these instructions](https://github.com/bycloudai/InstallVSBuildToolsWindows) might be helpful for people on Windows 11. \n",
|
||||
"\n",
|
||||
"## And for Mac people\n",
|
||||
"\n",
|
||||
"1. If you're new to developing on your Mac, you may need to install XCode developer tools. Here are [instructions](https://chatgpt.com/share/67b0b8d7-8eec-8012-9a37-6973b9db11f5).\n",
|
||||
"2. As with PC people, Anti-virus, Firewall, VPN can be problematic. These can interfere with installations and network access; try temporarily disabling them as needed"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f5190688-205a-46d1-a0dc-9136a42ad0db",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Step 1\n",
|
||||
"\n",
|
||||
"Try running the next cell (click in the cell under this one and hit shift+return).\n",
|
||||
"\n",
|
||||
"If this gives an error, then you're likely not running in an \"activated\" environment. Please check back in Part 5 of the SETUP guide for [PC](../SETUP-PC.md) or [Mac](../SETUP-mac.md) for setting up the Anaconda (or virtualenv) environment and activating it, before running `jupyter lab`.\n",
|
||||
"\n",
|
||||
"If you look in the Anaconda prompt (PC) or the Terminal (Mac), you should see `(llms)` in your prompt where you launch `jupyter lab` - that's your clue that the llms environment is activated.\n",
|
||||
"\n",
|
||||
"If you are in an activated environment, the next thing to try is to restart everything:\n",
|
||||
"1. Close down all Jupyter windows, like this one\n",
|
||||
"2. Exit all command prompts / Terminals / Anaconda\n",
|
||||
"3. Repeat Part 5 from the SETUP instructions to begin a new activated environment and launch `jupyter lab` from the `llm_engineering` directory \n",
|
||||
"4. Come back to this notebook, and do Kernel menu >> Restart Kernel and Clear Outputs of All Cells\n",
|
||||
"5. Try the cell below again.\n",
|
||||
"\n",
|
||||
"If **that** doesn't work, then please contact me! I'll respond quickly, and we'll figure it out. Please run the diagnostics (last cell in this notebook) so I can debug. If you used Anaconda, it might be that for some reason your environment is corrupted, in which case the simplest fix is to use the virtualenv approach instead (Part 2B in the setup guides)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7c8c0bb3-0e94-466e-8d1a-4dfbaa014cbe",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Some quick checks that your Conda environment or VirtualEnv is as expected\n",
|
||||
"# The Environment Name should be: llms\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"conda_name, venv_name = \"\", \"\"\n",
|
||||
"\n",
|
||||
"conda_prefix = os.environ.get('CONDA_PREFIX')\n",
|
||||
"if conda_prefix:\n",
|
||||
" print(\"Anaconda environment is active:\")\n",
|
||||
" print(f\"Environment Path: {conda_prefix}\")\n",
|
||||
" conda_name = os.path.basename(conda_prefix)\n",
|
||||
" print(f\"Environment Name: {conda_name}\")\n",
|
||||
"\n",
|
||||
"virtual_env = os.environ.get('VIRTUAL_ENV')\n",
|
||||
"if virtual_env:\n",
|
||||
" print(\"Virtualenv is active:\")\n",
|
||||
" print(f\"Environment Path: {virtual_env}\")\n",
|
||||
" venv_name = os.path.basename(virtual_env)\n",
|
||||
" print(f\"Environment Name: {venv_name}\")\n",
|
||||
"\n",
|
||||
"if conda_name != \"llms\" and venv_name != \"llms\" and venv_name != \"venv\" and venv_name != \".venv\":\n",
|
||||
" print(\"Neither Anaconda nor Virtualenv seem to be activated with the expected name 'llms' or 'venv' or '.venv'\")\n",
|
||||
" print(\"Did you run 'jupyter lab' from an activated environment with (llms) showing on the command line?\")\n",
|
||||
" print(\"If in doubt, close down all jupyter lab, and follow Part 5 in the SETUP-PC or SETUP-mac guide.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "45e2cc99-b7d3-48bd-b27c-910206c4171a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Step 1.1\n",
|
||||
"\n",
|
||||
"## It's time to check that the environment is good and dependencies are installed\n",
|
||||
"\n",
|
||||
"And now, this next cell should run with no output - no import errors. \n",
|
||||
"\n",
|
||||
"For people on the new version of the course (October 2025 on) - an error would suggest that you don't have the right kernel.\n",
|
||||
"\n",
|
||||
"For people on the original course:\n",
|
||||
"\n",
|
||||
"> Import errors might indicate that you started jupyter lab without your environment activated? See SETUP Part 5. \n",
|
||||
"> Or you might need to restart your Kernel and Jupyter Lab. \n",
|
||||
"> Or it's possible that something is wrong with Anaconda. If so, here are some recovery instructions: \n",
|
||||
"> First, close everything down and restart your computer. \n",
|
||||
"> Then in an Anaconda Prompt (PC) or Terminal (Mac), from an activated environment, with **(llms)** showing in the prompt, from the llm_engineering directory, run this: \n",
|
||||
"> `python -m pip install --upgrade pip` \n",
|
||||
"> `pip install --retries 5 --timeout 15 --no-cache-dir --force-reinstall -r requirements.txt` \n",
|
||||
"> Watch carefully for any errors, and let me know. \n",
|
||||
"> If you see instructions to install Microsoft Build Tools, or Apple XCode tools, then follow the instructions. \n",
|
||||
"> Then try again!\n",
|
||||
"> Finally, if that doesn't work, please try SETUP Part 2B, the alternative to Part 2 (with Python 3.11 or Python 3.12). \n",
|
||||
"> If you're unsure, please run the diagnostics (last cell in this notebook) and then email me at ed@edwarddonner.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "6c78b7d9-1eea-412d-8751-3de20c0f6e2f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# This import should work if your environment is active and dependencies are installed!\n",
|
||||
"\n",
|
||||
"from openai import OpenAI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b66a8460-7b37-4b4c-a64b-24ae45cf07eb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Step 2\n",
|
||||
"\n",
|
||||
"Let's check your .env file exists and has the OpenAI key set properly inside it. \n",
|
||||
"Please run this code and check that it prints a successful message, otherwise follow its instructions.\n",
|
||||
"\n",
|
||||
"If it isn't successful, then it's not able to find a file called `.env` in the `llm_engineering` folder. \n",
|
||||
"The name of the file must be exactly `.env` - it won't work if it's called `my-keys.env` or `.env.doc`. \n",
|
||||
"Is it possible that `.env` is actually called `.env.txt`? In Windows, you may need to change a setting in the File Explorer to ensure that file extensions are showing (\"Show file extensions\" set to \"On\"). You should also see file extensions if you type `dir` in the `llm_engineering` directory.\n",
|
||||
"\n",
|
||||
"Nasty gotchas to watch out for: \n",
|
||||
"- In the .env file, there should be no space between the equals sign and the key. Like: `OPENAI_API_KEY=sk-proj-...`\n",
|
||||
"- If you copied and pasted your API key from another application, make sure that it didn't replace hyphens in your key with long dashes \n",
|
||||
"\n",
|
||||
"Note that the `.env` file won't show up in your Jupyter Lab file browser, because Jupyter hides files that start with a dot for your security; they're considered hidden files. If you need to change the name, you'll need to use a command terminal or File Explorer (PC) / Finder Window (Mac). Ask ChatGPT if that's giving you problems, or email me!\n",
|
||||
"\n",
|
||||
"If you're having challenges creating the `.env` file, we can also do it with code! See the cell after the next one.\n",
|
||||
"\n",
|
||||
"It's important to launch `jupyter lab` from the project root directory, `llm_engineering`. If you didn't do that, this cell might give you problems."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "caa4837e-b970-4f89-aa9a-8aa793c754fd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"parent_dir = Path(\"..\")\n",
|
||||
"env_path = parent_dir / \".env\"\n",
|
||||
"\n",
|
||||
"if env_path.exists() and env_path.is_file():\n",
|
||||
" print(\".env file found.\")\n",
|
||||
"\n",
|
||||
" # Read the contents of the .env file\n",
|
||||
" with env_path.open(\"r\") as env_file:\n",
|
||||
" contents = env_file.readlines()\n",
|
||||
"\n",
|
||||
" key_exists = any(line.startswith(\"OPENAI_API_KEY=\") for line in contents)\n",
|
||||
" good_key = any(line.startswith(\"OPENAI_API_KEY=sk-proj-\") for line in contents)\n",
|
||||
" classic_problem = any(\"OPEN_\" in line for line in contents)\n",
|
||||
" \n",
|
||||
" if key_exists and good_key:\n",
|
||||
" print(\"SUCCESS! OPENAI_API_KEY found and it has the right prefix\")\n",
|
||||
" elif key_exists:\n",
|
||||
" print(\"Found an OPENAI_API_KEY although it didn't have the expected prefix sk-proj- \\nPlease double check your key in the file..\")\n",
|
||||
" elif classic_problem:\n",
|
||||
" print(\"Didn't find an OPENAI_API_KEY, but I notice that 'OPEN_' appears - do you have a typo like OPEN_API_KEY instead of OPENAI_API_KEY?\")\n",
|
||||
" else:\n",
|
||||
" print(\"Didn't find an OPENAI_API_KEY in the .env file\")\n",
|
||||
"else:\n",
|
||||
" print(\".env file not found in the llm_engineering directory. It needs to have exactly the name: .env\")\n",
|
||||
" \n",
|
||||
" possible_misnamed_files = list(parent_dir.glob(\"*.env*\"))\n",
|
||||
" \n",
|
||||
" if possible_misnamed_files:\n",
|
||||
" print(\"\\nWarning: No '.env' file found, but the following files were found in the llm_engineering directory that contain '.env' in the name. Perhaps this needs to be renamed?\")\n",
|
||||
" for file in possible_misnamed_files:\n",
|
||||
" print(file.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "105f9e0a-9ff4-4344-87c8-e3e41bc50869",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Fallback plan - python code to create the .env file for you\n",
|
||||
"\n",
|
||||
"Only run the next cell if you're having problems making the .env file. \n",
|
||||
"Replace the text in the first line of code with your key from OpenAI."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ab9ea6ef-49ee-4899-a1c7-75a8bd9ac36b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Only run this code in this cell if you want to have a .env file created for you!\n",
|
||||
"\n",
|
||||
"# Put your key inside the quote marks\n",
|
||||
"make_me_a_file_with_this_key = \"put your key here inside these quotes.. it should start sk-proj-\"\n",
|
||||
"\n",
|
||||
"# Change this to True if you already have a .env file and you want me to replace it\n",
|
||||
"overwrite_if_already_exists = False \n",
|
||||
"\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"parent_dir = Path(\"..\")\n",
|
||||
"env_path = parent_dir / \".env\"\n",
|
||||
"\n",
|
||||
"if env_path.exists() and not overwrite_if_already_exists:\n",
|
||||
" print(\"There is already a .env file - if you want me to create a new one, change the variable overwrite_if_already_exists to True above\")\n",
|
||||
"else:\n",
|
||||
" try:\n",
|
||||
" with env_path.open(mode='w', encoding='utf-8') as env_file:\n",
|
||||
" env_file.write(f\"OPENAI_API_KEY={make_me_a_file_with_this_key}\")\n",
|
||||
" print(f\"Successfully created the .env file at {env_path}\")\n",
|
||||
" if not make_me_a_file_with_this_key.startswith(\"sk-proj-\"):\n",
|
||||
" print(f\"The key that you provided started with '{make_me_a_file_with_this_key[:8]}' which is different to sk-proj- is that what you intended?\")\n",
|
||||
" print(\"Now rerun the previous cell to confirm that the file is created and the key is correct.\")\n",
|
||||
" except Exception as e:\n",
|
||||
" print(f\"An error occurred while creating the .env file: {e}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0ba9420d-3bf0-4e08-abac-f2fbf0e9c7f1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Step 3\n",
|
||||
"\n",
|
||||
"Now let's check that your API key is correct set up in your `.env` file, and available using the dotenv package.\n",
|
||||
"Try running the next cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0ee8e613-5a6e-4d1f-96ef-91132da545c8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# This should print your API key to the output - please follow the instructions that get printed\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"\n",
|
||||
"api_key = os.getenv(\"OPENAI_API_KEY\")\n",
|
||||
"\n",
|
||||
"if not api_key:\n",
|
||||
" print(\"No API key was found - please try Kernel menu >> Restart Kernel And Clear Outputs of All Cells\")\n",
|
||||
"elif not api_key.startswith(\"sk-proj-\"):\n",
|
||||
" print(f\"An API key was found, but it starts with {api_key[:8]} rather than sk-proj- please double check this is as expected.\")\n",
|
||||
"elif api_key.strip() != api_key:\n",
|
||||
" print(\"An API key was found, but it looks like it might have space or tab characters at the start or end - please remove them\")\n",
|
||||
"else:\n",
|
||||
" print(\"API key found and looks good so far!\")\n",
|
||||
"\n",
|
||||
"if api_key:\n",
|
||||
" problematic_unicode_chars = ['\\u2013', '\\u2014', '\\u201c', '\\u201d', '\\u2026', '\\u2018', '\\u2019']\n",
|
||||
" forbidden_chars = [\"'\", \" \", \"\\n\", \"\\r\", '\"']\n",
|
||||
" \n",
|
||||
" if not all(32 <= ord(char) <= 126 for char in api_key):\n",
|
||||
" print(\"Potential problem: there might be unprintable characters accidentally included in the key?\")\n",
|
||||
" elif any(char in api_key for char in problematic_unicode_chars):\n",
|
||||
" print(\"Potential problem: there might be special characters, like long hyphens or curly quotes in the key - did you copy it via a word processor?\")\n",
|
||||
" elif any(char in api_key for char in forbidden_chars):\n",
|
||||
" print(\"Potential problem: there are quote marks, spaces or empty lines in your key?\")\n",
|
||||
" else:\n",
|
||||
" print(\"The API key contains valid characters\")\n",
|
||||
" \n",
|
||||
"print(f\"\\nHere is the key --> {api_key} <--\")\n",
|
||||
"print()\n",
|
||||
"print(\"If this key looks good, please go to the Edit menu >> Clear Cell Output so that your key is no longer displayed here!\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f403e515-0e7d-4be4-bb79-5a102dbd6c94",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## It should print some checks including something like:\n",
|
||||
"\n",
|
||||
"`Here is the key --> sk-proj-blahblahblah <--`\n",
|
||||
"\n",
|
||||
"If it didn't print a key, then hopefully it's given you enough information to figure this out. Or contact me!\n",
|
||||
"\n",
|
||||
"There is a final fallback approach if you wish: you can avoid using .env files altogether, and simply always provide your API key manually. \n",
|
||||
"Whenever you see this in the code: \n",
|
||||
"`openai = OpenAI()` \n",
|
||||
"You can replace it with: \n",
|
||||
"`openai = OpenAI(api_key=\"sk-proj-xxx\")`\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "42afad1f-b0bf-4882-b469-7709060fee3a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Step 4\n",
|
||||
"\n",
|
||||
"Now run the below code and you will hopefully see that GPT can handle basic arithmetic!!\n",
|
||||
"\n",
|
||||
"If not, see the cell below."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cccb58e7-6626-4033-9dc1-e7e3ff742f6b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from openai import OpenAI\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"\n",
|
||||
"my_api_key = os.getenv(\"OPENAI_API_KEY\")\n",
|
||||
"\n",
|
||||
"print(f\"Using API key --> {my_api_key} <--\")\n",
|
||||
"\n",
|
||||
"openai = OpenAI()\n",
|
||||
"completion = openai.chat.completions.create(\n",
|
||||
" model='gpt-4o-mini',\n",
|
||||
" messages=[{\"role\":\"user\", \"content\": \"What's 2+2?\"}],\n",
|
||||
")\n",
|
||||
"print(completion.choices[0].message.content)\n",
|
||||
"print(\"Now go to Edit menu >> Clear Cell Output to remove the display of your key.\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "81046a77-c359-4388-929f-ffc8ad5cb93c",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true
|
||||
},
|
||||
"source": [
|
||||
"## If the key was set correctly, and this still didn't work\n",
|
||||
"\n",
|
||||
"### If there's an error from OpenAI about your key, or a Rate Limit Error, then there's something up with your API key!\n",
|
||||
"\n",
|
||||
"First check [this webpage](https://platform.openai.com/settings/organization/billing/overview) to make sure you have a positive credit balance.\n",
|
||||
"OpenAI requires that you have a positive credit balance and it has minimums, typically around $5 in local currency. My salespitch for OpenAI is that this is well worth it for your education: for less than the price of a music album, you will build so much valuable commercial experience. But it's not required for this course at all; the README has instructions to call free open-source models via Ollama whenever we use OpenAI.\n",
|
||||
"\n",
|
||||
"OpenAI billing page with credit balance is here: \n",
|
||||
"https://platform.openai.com/settings/organization/billing/overview \n",
|
||||
"OpenAI can take a few minutes to enable your key after you top up your balance. \n",
|
||||
"A student outside the US mentioned that he needed to allow international payments on his credit card for this to work. \n",
|
||||
"\n",
|
||||
"It's unlikely, but if there's something wrong with your key, you could also try creating a new key (button on the top right) here: \n",
|
||||
"https://platform.openai.com/api-keys\n",
|
||||
"\n",
|
||||
"### Check that you can use gpt-4o-mini from the OpenAI playground\n",
|
||||
"\n",
|
||||
"To confirm that billing is set up and your key is good, you could try using gtp-4o-mini directly: \n",
|
||||
"https://platform.openai.com/playground/chat?models=gpt-4o-mini\n",
|
||||
"\n",
|
||||
"### If there's a cert related error\n",
|
||||
"\n",
|
||||
"If you encountered a certificates error like: \n",
|
||||
"`ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)` \n",
|
||||
"Then please replace:\n",
|
||||
"`openai = OpenAI()` \n",
|
||||
"with: \n",
|
||||
"`import httpx` \n",
|
||||
"`openai = OpenAI(http_client=httpx.Client(verify=False))` \n",
|
||||
"And also please replace: \n",
|
||||
"`requests.get(url, headers=headers)` \n",
|
||||
"with: \n",
|
||||
"`requests.get(url, headers=headers, verify=False)` \n",
|
||||
"And if that works, you're in good shape. You'll just have to change the labs in the same way any time you hit this cert error. \n",
|
||||
"This approach isn't OK for production code, but it's fine for our experiments. You may need to contact IT support to understand whether there are restrictions in your environment.\n",
|
||||
"\n",
|
||||
"## If all else fails:\n",
|
||||
"\n",
|
||||
"(1) Try pasting your error into ChatGPT or Claude! It's amazing how often they can figure things out\n",
|
||||
"\n",
|
||||
"(2) Try creating another key and replacing it in the .env file and rerunning!\n",
|
||||
"\n",
|
||||
"(3) Contact me! Please run the diagnostics in the cell below, then email me your problems to ed@edwarddonner.com\n",
|
||||
"\n",
|
||||
"Thanks so much, and I'm sorry this is giving you bother!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "dc83f944-6ce0-4b5c-817f-952676e284ec",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Gathering Essential Diagnostic information\n",
|
||||
"\n",
|
||||
"## Please run this next cell to gather some important data\n",
|
||||
"\n",
|
||||
"Please run the next cell; it should take a minute or so to run. Most of the time is checking your network bandwidth.\n",
|
||||
"Then email me the output of the last cell to ed@edwarddonner.com. \n",
|
||||
"Alternatively: this will create a file called report.txt - just attach the file to your email."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "248204f0-7bad-482a-b715-fb06a3553916",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Run my diagnostics report to collect key information for debugging\n",
|
||||
"# Please email me the results. Either copy & paste the output, or attach the file report.txt\n",
|
||||
"\n",
|
||||
"!pip install -q requests speedtest-cli psutil setuptools\n",
|
||||
"from diagnostics import Diagnostics\n",
|
||||
"Diagnostics().run()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e1955b9a-d344-4782-b448-2770d0edd90c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user