Setting API Keys
Since ChatLab builds upon OpenAI's Chat Models and Function Calling, you must sign up with OpenAI and get an API key. You can find your API key on your OpenAI account page. Once you have your key, set it to the OPENAI_API_KEY
environment variable.
Jupyter
Before launching JupyterLab (or the classic notebook), set the OPENAI_API_KEY
environment variable.
export OPENAI_API_KEY=<your key>
jupyter lab
As an alternative, you can use the dotenv package to load the environment variable from a .env
file.
pip install python-dotenv
Create a .env
file in the same directory as your notebook and add the following line.
OPENAI_API_KEY=<your key>
Colab, Kaggle, and other cloud notebooks
Just getpass
This is the most secure way to set your API key that works with all notebooks. It will prompt you for your key every time you run a notebook. This is the recommended way to set your API key if other methods do not work.
import os
from getpass import getpass
os.environ['OPENAI_API_KEY'] = getpass('Enter your OpenAI API Key: ')
The %env
magic
This options is insecure, but easy. It will leave your key in the notebook for others to see. This is not recommended for sharing notebooks.
If you absolutely, positively have to, you can set the OPENAI_API_KEY
environment variable in the notebook with the %env
magic.
%env OPENAI_API_KEY=<your key>
Good luck!