Skip main navigation

Hands-on labs and homework exercises instructions

How to setup your local environment to execute the Jupyter notebooks used as hands-on labs and homework exercises.

Jupyter Notebooks Execution

The course includes a set of Jupyter notebooks for hands-on labs and homework exercises.

Prerequisites

The labs and exercises use APIs from OpenAI, Anthropic, and Cohere. You will need to get API keys from each to execute them. A secure and simple way to use the API keys is to create a local .env file and put the keys, for example:

OPENAI_API_KEY=sk-proj-###
ANTHROPIC_API_KEY=sk-ant-###
CO_API_KEY=3lljis###

The notebooks get access to the API keys using:

from dotenv import load_dotenv
load_dotenv()

Notebook Execution Options

You have a few options to execute the Jupyter notebooks:

1. Local Jupyter Notebook Server

Set up your local environment to run the Jupyter notebooks. Follow these steps:

git clone https://github.com/guyernest/advanced-rag.git
cd advanced-rag
pip install uv
uv venv --python cpython-3.12.3-macos-aarch64-none # Create a virtual environment with python 3.12 for MacOS with Apple Silicon (adapt as needed to your machine)
source .venv/bin/activate
uv pip compile requirements.in --output-file requirements.txt # Create the requirements.txt file for the environment
uv pip install requirements.txt # Install the required dependencies in the environment
uv pip install jupyterlab ipykernel # Install Jupyter Lab and ipykernel to manager kernels for Jupyter
python -m ipykernel install --user --name=.venv --display-name="Python (.venv)" # Create kernel from the virtual environment
jupyter lab

Jupyter Lab Setup Screencast

Choose the recently created kernel from the kernel list on the top right of Jupyter lab:
Jupyter Lab Kernel Selection
jupyter Kernel Selection

Please note that the instructions above are using , which speeds up dependency management. It supports Windows, MacOS, and Linux. Check the detailed instructions for its installation and usage here: https://github.com/astral-sh/uv.

2. Jupyter Notebook Support within Visual Studio Code

Visual Studio Code (VSC) has built-in support for Jupyter notebooks. Follow these steps:

git clone https://github.com/guyernest/advanced-rag.git
cd advanced-rag
code .

Once VSC is opened in the course directory, open a terminal and execute the following commands:

pip install uv
uv venv --python 3.11.0
source .venv/bin/activate
uv pip compile requirements.in --output-file requirements.txt
uv pip install requirements.txt

Alternatively, you can use the traditional pip route by:

python -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt

If your VSC doesn’t have Jupyter support yet, you will need to install ipykernel:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # get the pip package
python get-pip.py # Install the pip package
python -m pip install ipykernel # Install ipykernel to add the support for Jupyter notebooks to VSC

This article is from the free online

Advanced Retrieval-Augmented Generation (RAG) for Large Language Models

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now