A Jupyter/IPython magic command for generating code using GPT

BIF-0003

Coding with ChatGPT is a lot of fun! Here’s a Jupyter/IPython magic that allows you to write your request and have the model describe it and create a new cell for the actual code. Hopefully a timesaver for you notebook-rocking users out there.

ChatGPT powered JupyterLab

Install using pip

pip install gpt-magic

Set an environment variable called OPENAI_API_KEY with your API key from OpenAI.

import os
os.environ["OPENAI_API_KEY"] = "your_openai_api_key_here"

Load it in Jupyter or JupyterLab

%load_ext gpt

Generate code using the %gpt magic

%gpt create a function to strip all spanish stop words from a string