How to use ChatGPT’s new “Code Interpreter” feature
A game-changing feature for not just programmers and data experts, but general users as well. Analyze data, test code, make charts, solve math, and more.
Aug 31, 2023 • 8 Minute Read
- IT Ops
- Software Development
- AI & Machine Learning
(Update 31 Sept 2023: The Code Interpreter feature is now known as Advanced Data Analytics. Besides the name change, it remains exactly the same).
Ever since ChatGPT’s new plugin feature was introduced, programmers and data professionals have been eagerly waiting for one particular plugin to go live: code interpretation. The name is a bit misleading — it’s actually an incredibly useful feature for most professionals, not just coders. And since this new feature has just entered open beta, if you’ve got ChatGPT Pro, you can now try it out!
We share what you can do with this new plugin with demonstrative examples, and how you can set up this new feature
Table of contents
- What is ChatGPT Code Interpreter?
- What can I do with the Code Interpreter plugin? (With examples)
- How do I activate the ChatGPT code interpreter plugin? A step-by-step guide
- How to upload files to ChatGPT with Code Interpreter
- How to download files from ChatGPT with Code Interpreter
- Further learning
What is ChatGPT Code Interpreter?
ChatGPT has a lot of limitations. It's bad at math, you can’t upload or download anything (like if you wanted to show it a diagram to analyze), it can’t make charts, and it can’t run code directly in the interface. Code Interpreter changes all that, allowing you to do all of the above.
What can I do with the Code Interpreter plugin? (With examples)
There’s a lot of functionality in this one plugin, so let’s break it down!
1. Data analysis and visualization
Because you can upload files, that means you can hand over a file full of raw business data (Like a CSV, Excel spreadsheet, SQL database, etc) and get an AI to give you insights. Let me show you how absolutely disruptive this is in practice.
Example: Creating a map from CSV data
And ChatGPT doesn’t turn down the job, jumping to it.
Here’s the map that it created from the data set, taking all of one minute to generate.
Of course, that’s a bit messy, so I refined it a little by asking it to color code the heritage markers a bit more (green for natural, red for cultural, and purple for mixed).
It’s pretty easy to imagine doing this with any business data: data center locations, competitor stores, housing price opportunities. But maps are just one type of visualization; what if we wanted to do charts?
Example: Creating a chart from CSV data
Let’s put another lazy prompt into ChatGPT, using the same data. Obviously, the more specific we get the better the outcome, but for this example I'm shooting from the hip.
It decided to do a bar chart on the number of World Heritage Sites per country, and gave me a handy PNG I could download.
Now imagine doing this with SEO or consumer data, or pretty much any other business insight you might want. It’s pretty much like having an entry-level analyst you can handball to. In practice, you might want to make sure you’re taking ethics and privacy into account with all the data you’re feeding ChatGPT, especially since OpenAI is not immune to data breaches.
Example: Working with more data modeling
All right, all of this is still pretty lightweight. Let’s give it a single column of training data on daily BTC to USD exchange rates (how many US dollars are needed to buy 1 bitcoin).
Normally, I might load this data into RStudio using scan(), plot the daily prices using plot, set up xlab, ylab and type arguments. Here’s what my chart would look like after all that annoying work.
And here’s what ChatGPT does after giving it a simple prompt and the data file.
It’s almost exactly the same. In fact, I’d say ChatGPT has done a little bit better, taking the initiative on more date specificity and color contrast. It also took a fraction of the time.
Caveat: ChatGPT still can’t actually look at charts
One area that even a junior human analyst beats out ChatGPT is analyzing data visually. We tried to feed ChatGPT photos and PDFs with the simplest of charts and questions, only to have it request it in text-based format or raw data. So if you can read the snapshot above and notice “China has the most world heritage sites”, you’re still (currently) got an edge over ChatGPT.
2. For code (obviously)
Never has there been a bigger spoiler dropped since the ending of James Cameron’s Titanic. One of the biggest annoyances of using ChatGPT to write code is prior to this update, you simply couldn't trust it.
I’ve watched it make up functions that simply don’t exist and had to correct it, feeling like a frustrated mentor. Or worse, you run some code that ChatGPT has dreamed up only to have it throw up dumb run-time errors because of the simplest syntax issues (I’m perfectly capable of missing semicolons on my own, thanks).
You know what would fix that? If ChatGPT could just run and test the code in a sandbox, firewalled environment and make sure it works before handing it to me (“Test your damn work first, bot.”). And that’s exactly what Code Interpreter lets it do! The code is evaluated in a persistent session that lasts for the duration of the chat (with an upper-bound timeout) and subsequent calls can build on each other.
The big limitation is it currently runs a Python interpreter, which means if you’re working with other languages, obviously it’s not there yet. But having the plugin turned on seems to greatly improve ChatGPT’s ability to interpret code in general.
Example: Getting it to spin up and test Python code
Of course it didn’t test it, because I didn’t specify. That's on me, and a prime example of poor prompt engineering! So I specifically asked it to run the test, and it did.
Much better! Keep in mind that even if it’s testing its own code, you should treat it just like a human and not just push directly to production. Whether it’s coding or any other business process, Gen AI is strongest when you build business processes around it to mitigate any potential risks from using it.
This means code reviewing what ChatGPT produces, testing it yourself, limiting the scope of deployment, sandboxing the generated code, and having a rollback strategy. It’s the same for tools like self-fixing and auto-code AI: make sure you’re not just blindly accepting the code that ChatGPT is feeding you.
3. Math equations
If you hate (nay, omniloathe) math like me, you probably want to handball it to a computer. ChatGPT has been famously bad at math because it’s simply guessing the next word in a sentence. However, now it can build Python code to solve problems, and it does this fairly well.
Example: Solving simple, text-based math
It’s correct, but as any student knows, you can’t just have the answer - you’ve got to show how you got there. So let’s get ChatGPT to show us their logic.
Looks sound. That was a pretty easy question, though. Could we give it something more qualitative?
Example: Asking ChatGPT to solve qualitative math
Pulling out one of my old academic textbooks, I asked ChatGPT to solve a recurrence relation question to see how it went.
The answer it gave was right on the money, 5*(−1)^n, something that wouldn’t have happened without the plugin installed.
Just think of all the math teachers who now have to worry about students uploading equations and getting the full answer, including the workings!
How do I activate the ChatGPT code interpreter plugin? A step-by-step guide
Access to this new feature is pretty straightforward. First, you need access to ChatGPT Plus, since ChatGPT plugins aren’t available on free accounts. Upgrading to ChatGPT Plus is simple: just go into ChatGPT and click on “Upgrade to Plus” in the bottom right corner, then follow the purchase steps.
Once you’ve done that, return to ChatGPT and follow these steps.
- In the bottom right corner, click on your account name.
- Click on Settings.
- In the Setting menu, click on Beta features.
- Click on the Code Interpreter toggle. You don’t need to activate the plugin beta feature or go through the ChatGPT plugin store.
- Go to create a new prompt and hover over GPT-4 at the top. There should now be a dropdown that allows you to switch between the standard and Code Interpreter powered version of GPT-4.
- Click on the Code Interpreter option.
- The Code Interpreter plugin mode is now enabled! To use it, make sure this is selected when you start up a new chat.
How to upload files to ChatGPT with Code Interpreter
When you have the Code Interpreter plugin enabled, there will be a little plus icon on the left side of your text box. You can use this to upload files like Excel and Word docs, text files, you name it. However, ChatGPT will only recognise things that are text-based, so while you can upload images and PDFs, it currently can’t make sense of them.
How to download files from ChatGPT with Code Interpreter
When you are in a chat conversation with ChatGPT and the Code Interpreter plugin is active, ask in the prompt for a download. It will provide a link in the chat to the file. Click on it and you will be able to download the file. This is particularly useful if you ask it to produce reports.
Be aware that with graphs, ChatGPT seems to use matplotlib and has issues with the saving of files, leading to parts being cropped off. Keep asking for an image without the cropping, and it will eventually produce one with more white space and no cropping.
Further learning materials
Pluralsight offers a range of beginner, intermediate, and expert AI and ML courses, including dedicated courses on generative AI and tools like ChatGPT. You can sign up for a 10-day free trial with no commitments. Why not check our courses out and get over a week of professional learning at zero cost?
Alternatively, if you want to read more educational articles like this one, check these out: