In this tutorial, we will install the necessary tools and run a simple openai-cookbook notebook to learn how to use the openai API.
- To use the OpenAI API, get an OpenAI API key from the OpenAI site. You need to create an account and enter your credit card information.
OPENAI_API_KEYto the OS environment variable. To add it in Windows OS, go to windows menu > Settings > System > About > "Advanced System Settings" popup, click Environment Variables button, Click the add button on System Variables, enter
OPENAI_API_KEYas the variable name and your API key as the variable value.
Using Jupyter Notebook on PC
JupyterLabis the next generation web-based interactive development environment that replaces
Miniconda- a minimalized version of a package manager that allows you to manage virtual environments and install packages in
Python(other languages besides
Commands for creating virtual environments when using
Miniconda, allowing you to run multiple versions of
Python in separate environments by creating different environments.
conda create -n "virtual-env-name" python=3.8- creates a virtual environment with a specific name with a specific version of
conda info -e- get a list of virtual environments
conda activate "virtual-env-name"- activates the virtual environment with the specified name
conda deactivate- deactivates(exit) a virtual environment
conda remove -n "virtual-env-name" --all- remove a virtual environment with the specified name
INstalling and running JupyterLab
Here is the installation sequence
- install Miniconda (include
Pythonin the installation file)
- On Windows, after completing the installation with the installation file, "Anaconda Powershell Prompt (miniconda3)" is created in the menu. Press it to run it.
- Check if the OPENAI_API_KEY environment variable is set correctly with the command
conda create -n openai python=3.8- Create a virtual environment with the name "openai" in python 3.8 version.
conda activate openai- Activate the virtual environment created
pip install jupyterlab- Install JupyterLab
pip install tenacity tiktoken openai "openai[datalib]"- Install the OpenAI API related libraries
jupyter lab .- Run
JupyterLabwith the current directory (
.) as the root of the notebook, and automatically open the browser to display the
Explore the OpenAI API Cookbook
JupyterLab locally by
examples/Embedding_long_inputs.ipynb notebook and run it.
[Youtube1 - Follow along]