In a previous article, we looked at a VSCode extension with ChatGPT-like functionality. Today we will see how to integrate ChatGPT into Jupyter Notebooks, which will be very useful for anyone who works with data.
You heard that right! You can get ChatGPT functions such as format, explain, debug, complete and review directly from a Jupyter Notebook.
Let's dive into it!
How to add the ChatGPT extension to Jupyter Notebooks
First of all, this is a browser extension powered by GPT-4, which means we have to download it from the web store.
If you use Chrome, go to this website and install the extension; if you use Firefox, you can install it locally by following the steps here.
After installing the extension, open the settings window. You should select the OpenAI API, choose the model you want to use and enter your OpenAI API key, which you can find here.

Note: if the “Which AI Provider do you want to use?” prompt shows an endless loading circle and your API key is not saved, open the regular ChatGPT page, send a message there, then return to the settings page and refresh it. You should now see the image above (for other issues like this, visit the GitHub repo).
If you do not have an API key, you can create one by following the steps shown in the image below.

Once your key is saved, you can open Jupyter Notebook in Chrome. After opening or creating a new notebook, you will notice new buttons on the toolbar.

Let's explore what they do.
Note: if you are a Mac user and Safari is your default browser, you must change the default browser to Chrome or Firefox to work with the installed extension. To make Chrome the default browser, click the three dots, then Settings, and select “Default browser ” from the left panel.
Format code
This extension lets you add comments and docstrings to your cell and format it automatically. To do so, click the button below and you will automatically get an improved version of the code.
Here is an example with a Python function.

As you can see, the extension added docstrings and comments to our code.
Explain code
With this extension, you can explain the contents of your code cell in ELI5 style. Just click the “Explain” button and a window will appear with a thorough explanation of the code cell.

Debug code
You can easily debug an error message in your code cell and get an explanation of the error (just as with ChatGPT) using the ” Debug “ button.
As you can see, ChatGPT found a typo in my code and suggested replacing date with dates.

Complete code
One of my favourite functions of this extension is code completion. It lets you complete a code snippet in your code cell. Just leave a comment with the instructions and add some code if needed.
Here is an example.

As you can see, we only needed a comment and a list of samples to generate the code we wanted.
More functions
There are other things you can do with this extension, such as running a code review of your code cell, asking ChatGPT questions, and even asking ChatGPT a question through your microphone.
Just keep in mind that if you use the voice command feature, you will need the OpenAI Whisper API, which costs $0.006 per minute.

