~ 7 min read

ChatGPT Code Interpreter: The Best Use Cases for Developers

ChatGPT’s code interpreter plugin has just become available for all ChatGPT plus subscribers. That means if you’re a paid up subscriber, you’re going to be able to run Python code written by ChatGPT and see immediate results in your browser.

I went through a huge number of use cases and here I’ll highlight the best ways developers can use it.

Setup

To enable it you need to head into settings and flip the toggle for it in beta features. Once you do that, you’ll get a code interpreter option as part of the gpt-4 model dropdown.

The code interpreter model selection dropdown

Testing Code

I wanted to see how code interpreter would cope with writing some new code for something most developers find difficult, regular expressions.

I set it the task of matching uk mobile numbers from a string, including a variety of country code formats preceding each number.

ChatGPT happily responded with an regex, but like any lazy developer, only realised that its suggestion didn’t work when I asked it to test against my original examples.

Here’s where code interpreter shines. As it has the ability to execute code rather than just conjure it up, it can see where things fail. When it actually ran the suggested regex through code interpreter it identified it needed to mock some data. It immediately did so and proceeded to test the mock data and iterate on the regex until every one of the examples passed.

After every change it makes, it outlines the steps it used through a dropdown, giving you access to the exact python code. This means that you can download it and use it offline if you like.

Code Interpreter Regex Example

It even was able to adjust the regex further since I identified it hadn’t factored in optional leading zeroes which I’d originally requested.

Being able to farm these sort of mundane tasks out to something that is able to iterate this quickly is, I think, a massive win for developers. The fact we can now test it without having to download it first, insert it into a new file or fire up a new environment. We have an accessible sandbox isolated away that we can work with.

Code Review

Code Interpreter gives the option of being able to upload files for it work with. You can have it look through pdfs, work with images and even video.

At the time of publishing, the upload size is limited to 100MB and you can only upload a single file each time, but a sneaky way round this is to zip your files since code interpreter can extract the data within.

I uploaded some old code from an Advent of Code challenge for it to review since I was interested to see if it could understand it.

My code reads some data about monkeys from a file and performs a number of operations to values for each monkey it describes. It isn’t trivial, but code interpreter was able to understand what it did giving me a couple of options for refactoring it.

Code Interpreter Reviews My Code

It even generated some mock data that the code would parse and adjusted it once it realised that some of it’s assumptions about the data could send it into an infinite loop.

Data Analysis

Data analysis was one of the first things I did when I got access to code interpreter. I asked it simply what was in a csv of Unemployment data I got from the ONS and could it show me any graphs to highlight interesting aspects of it.

I was really impressed to see the first thing code interpreter said was the data was formatted in a non-standard way needed some cleanup.

It correctly identified that the header had a number of rows that would need to be removed before it be read could start working with it.

Code Interpreter correctly asserts it needs to clean dirty data

If you’ve ever had to do any form of data analysis yourself, you know factoring in various edge cases in order to clean it up is another laborious task that it’s worth getting AI to do.

From this it continued on stating a whole bunch of facts about the data and it proceeded to then draw two charts to visualise the data.

  • A line plot to visualise the overall trend over time.
  • A box plot to show the annual distribution of the unemployment rate

I was blown away that it did all this from a single initial prompt, with multiple steps with no interaction from me. This is going to make it incredibly easy for those with little to no experience working with data like this quickly find insights.

Data Visualisation

I uploaded a dataset of movies that I got from kaggle. The dataset is zipped, which ChatGPT is able to handle and unzip with Python. It correctly extracted and identified the data within, showing me a preview of the rows and columns within.

Code Interpreter Quickly Identifies Data within Files

I then asked ChatGPT to draw some “non-obvious insights” on the data I uploaded. It chose the following:

  • Correlation between budget and success of a movie
  • Impact of a directors experience on the success of a movie
  • Trend of movie genres over time

I asked it to graph these insights using it’s own choice of graphs - in order to do so, it needed to add a number of columns. It was able to extract and rework the data with new columns for things like year, all the while informing me of the pretty major steps it had taken to do so. It came back with some great scatter plots and a line chart for movie genre trends. I was able to write this out to a pdf.

I was able to identify that the data it had graphed has some errors in it, since one director appeared to have directed over 300 movies. After asking ChatGPT who that was, it transpired that had included directors whose name was missing as a single dataset.

Director 300 Movies

Finally it was able to list some key takeaways “while factors like budget and director’s experience may have some influence on a movie’s financial success and ratings, they’re not the sole determinants.”

Visualisation for Directors Experience

It’s pretty amazing to me it’s possible to have most of this legwork done very quickly with relatively little input from me. We’ve simply uploaded some data. It’s so accessible to anyone to interpret data in next to no time with just a web browser.

Image Analysis

I successfully was able to get ChatGPT to highlight the outline of a screenshot of me, though it’s difficult to make out in the image below. However, it failed fairly poorly when asked to zoom in and make me centre of the frame. It didn’t have the necessary libraries installed to do anything complex and couldn’t download them. Instead it suggested I do that myself and gave me the code to try it out. I created a gist of every Python library code interpreter has installed which you can find here.

Image Edge Detection

I was also able to get it to extract dominant colours from images using k-means clustering and output a list of hex codes. This could come in handy if you want to create web designs themed around particular images for instance.

K-Means Clustering Image Colour Extraction

Final Thoughts

It’s important to note that the data your uploading is being shared with OpenAI, who is confusingly a private company. I’d be hesitant at this point to be uploading anything sensitive and definitely wouldn’t be sharing anything private like bank statements for it to look at (something I’ve seen suggested by some YouTubers).

It’s pretty crazy that a year ago this product didn’t even exist and it’s rapidly becoming a go to assistant for development. I’m pretty excited to see what I can do with future plugins that get released.

Subscribe for Exclusives

My monthly newsletter shares exclusive articles you won't find elsewhere, tools and code. No spam, unsubscribe any time.