Computer

ChatGPT Code Interpreter: what it is and how to use it for free

ChatGPT Code Interpreter: what it is and how to use it for free

The plugins that OpenAI is releasing for its chatbot ChatGPT they are revealing themselves as a real “gold mine”. One of the most promising add-ons is called ChatGPT Code Interpreter and allows you to perform complex processing starting from Python code hosted locally, on the user’s device.

As OpenAI explains, Code Interpreter rests its operation on a the Python interpreter running within an environment sandboxed, protected by firewall and able to benefit from disk space. Compared to the classic approach offered by ChatGPT, with Code Interpreter developers, professionals and end users can exploit the power and versatility of generative models to request automatic data processing and carry out operations in a completely automated way.

What is ChatGPT Code Interpreter and how it works

Through the use of ChatGPT Code Interpreter, it is possible to ask the generative models developed and updated by OpenAI, for example, to perform analyzes and data visualizationsextract useful information from a dataset, create graphs, convert a PDF file containing scans of paper pages into a document with selectable and searchable text, trim an audio or video file and change its format, manipulate images and much more.

ChatGPT Code Interpreter supports a large number of file formats including TXT, PDF, DOC, DOCX, JPEG, PNG, MP4, AVI, CSV, JSON, XML, XLS, XLSX, CPP, PY, HTML, PDF, DB, SQLite. Needless to say, therefore, that the system opens the door to a wide range of possible processing on a large number of dataset (dataset).

OpenAI didn’t mention any limitations for the file size manageable with Code Interpreter: following some tests, it is possible to state that the system is still able to process files larger than 180 MB.

On the Python side, however, this is the package list that Code Interpreter can use and that users are therefore free to use in their projects.

Basically, Code Interpreter can only be used by users who have subscribed to a subscription plan ChatGPT Plus at $20 a month. Also, you are required to enable the GPT-4 template from your account’s admin panel.

How to use ChatGPT Code Interpreter for free with a free account

An independent developer has found a way to use Code Interpreter gratis with an equally free OpenAI account. Below we see how to proceed in Windows environment but the same operations can also be done on other platforms.

It is important to highlight that OpenAI offers $5 free credit for all new accounts – you must use a telephone number mobile not linked to other user accounts already registered on the platform. Such free credithowever, it is not valid indefinitely and always expires after approximately 3 months of account registration.

The code we present below therefore only works for users who have a account free OpenAI whose credit has not yet expired. The section Usage show the Expiration date of credit. Instead, click on Rate limits you also get the list of generative models that can be used by calling them directly from Python code.

Install Python and PIP on Windows

Essential requirement to use Code Interpreter in Windows is the installation of Python and the system management of PIP packets (PIP Installs Packages). PIP is used to install and manage bookstores e moduli external ones that greatly expand the functionality of the Python language. It greatly simplifies the installation process and dependency management of a Python project.

After downloading Python, you must start its installation, taking care to tick both boxes in the figure and then click on Customize installation.

Python installation on Windows

In the following screen, you must check all the boxes present and then press the button again Next to continue installing and configuring Python and PIP.

Python and PIP configuration

Inside the next screen Advanced Optionsyou can leave everything unchanged then click on the button Install.

At the end of the procedure, you can type cmd in the Windows search box then choose Run as administrator. The following two commands return the version number of Python and PIP, confirming that both components are installed correctly:

python --version

pip --version

Verify Python PIP installation

Once done, you may need to update PIP using the following command:

python -m pip install --upgrade pip

You can then proceed with the installation of Code Interpreter API:

pip install codeinterpreterapi

Use Code Interpreter to create a graph by gathering information from the web

At the basis of the functioning of the code proposed below is the use of Jupyter, an open source web application that allows you to create and share documents containing interactive code, visualizations, text and media. It is widely used by data scientistfor data analysis activities, in the field of scientific research and in the machine learning.

He big advantage of Code Interpreter is that depending on the prompt of the user or of the request advanced by the latter using the natural language (also supported in the Europen language, as in ChatGPT), the necessary modules are used to manage it adequately.

Take the following Python code from this GitHub page as an example:

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

os.environ["VERBOSE"] = "True"

from codeinterpreterapi import CodeInterpreterSession

async def main():
# create a session
session = CodeInterpreterSession(model="gpt-3.5-turbo")
await session.astart()

# generate a response based on user input
response = await session.generate_response(
"""Crea un grafico che rappresenta il valore
delle azioni Apple dal 2007 a giugno 2023."""
)

# output the response (text + image)
print("AI: ", response.content)
for file in response.files:
file.show_image()

# terminate the session
await session.astop()

if __name__ == "__main__":
import asyncio
# run the async function
asyncio.run(main())

With this simple Python code, to be pasted into a text editors and save locally in a folder of your choice, you ask Code Interpreter to collect the value of Apple shares from 2007 to “today” and then automatically create a graph that represents the trend over time.

Saving the file as chart.py then typing the following at the Windows command prompt results in a graph starting with the request made using pure text:

python chart.py

ChatGPT Code Interpreter API

In the code proposed above, instead of PASTE_API_KEY_OPENAIit is essential to enter your own API key OpenAI generated through this page. The advantage of the example Python code is that it also supports the use of the model GPT-3.5.

Code Interpreter to process the contents of a spreadsheet

Another example of usage could be thedata mining important from a spreadsheet provided as input together with the prompt. The author of the project posted on GitHub shared the following code, which we republish in a slightly revised form:

import os
os.environ["OPENAI_API_KEY"] = "INCOLLARE_API_KEY_OPENAI"
os.environ["VERBOSE"] = "True"

from codeinterpreterapi import CodeInterpreterSession, File

async def main():
# context manager for auto start/stop of the session
async with CodeInterpreterSession(model="gpt-3.5-turbo") as session:
# define the user request
user_request = """Analizza questo dataset e 
crea un grafico con i film più popolari."""
files = [
File.from_path("tmdb_5000_movies.csv"),
]

# generate the response
response = await session.generate_response(
user_request, files=files
)

# output to the user
print("AI: ", response.content)
for file in response.files:
file.show_image()

# terminate the session
await session.astop()

if __name__ == "__main__":
import asyncio
asyncio.run(main())

In our case we tried to use like input the TMDB 5000 Movie Dataset CSV file. It is an archive that contains all the information on films launched on the market over the years.

Then try saving the Python code with the name film.py then to store, in the same folder, the CSV file from the name tmdb_5000_movies.csv. In response to the text request “Analyze this dataset and create a graph with the most popular movies“, Code Interpreter will generate a graph similar to the one below. Sorry if it’s too little.

To make “the magic”, just type python film.py at the Windows command prompt.

Demonstration ChatGPT Code Interpreter

Using the same approach, with a little inventiveness, it is possible to process any kind of file by extracting potentially very useful information for any profession and work activity.

Leave a Reply

Your email address will not be published. Required fields are marked *