Using the OpenAI API Library 1 - Installing JupyterLab
- Published on
Overview
In this tutorial, we will install the necessary tools and run a simple openai-cookbook notebook to learn how to use the openai API.
Preparation
- 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.
- Add
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, enterOPENAI_API_KEYas the variable name and your API key as the variable value.
Using Jupyter Notebook on PC
Preparation
JupyterLabis the next generation web-based interactive development environment that replacesJupyter Notebook.Miniconda- a minimalized version of a package manager that allows you to manage virtual environments and install packages inPython(other languages besidesPython?!)
Miniconda
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 ofPython.conda info -e- get a list of virtual environmentsconda activate "virtual-env-name"- activates the virtual environment with the specified nameconda deactivate- deactivates(exit) a virtual environmentconda 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
echo $Env:OPENAI_API_KEY
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 createdpip install jupyterlab- Install JupyterLabpip install tenacity tiktoken openai "openai[datalib]"- Install the OpenAI API related librariesjupyter lab .- RunJupyterLabwith the current directory (.) as the root of the notebook, and automatically open the browser to display theJupyterLabwebpage.
Explore the OpenAI API Cookbook
Run JupyterLab locally by cloning with git.
Find the examples/Embedding_long_inputs.ipynb notebook and run it.
[Youtube1 - Follow along]