codeinterpreterapi: A Developer’s Dream Tool — ChatGPT Code Interpreter for Free💭

Manoj Das
3 min readAug 4, 2023

--

How to Use ChatGPT Code Interpreter for Free? What is codeinterpreterapi?

Photo by Darius Bashar on Unsplash

Codeinterpreterapi is a LangChain implementation of the ChatGPT Code Interpreter. Using CodeBoxes as backend for sandboxed python code execution. CodeBox is the simplest cloud infrastructure for your LLM Apps. You can run everything local except the LLM using your own OpenAI API Key.

OpenAI has recently introduced the Code Interpreter in ChatGPT exclusively for paying users at a monthly cost of $20. Nevertheless, this price point might not be accessible to everyone. If you are seeking a free alternative to leverage ChatGPT’s Code Interpreter, you’re in luck! A talented developer named Shroominic has created an open-source version of ChatGPT’s Code Interpreter. With this implementation, you can conduct dataset analysis and visualize data just like with ChatGPT. Let’s dive into the tutorial and explore how you can use Code Interpreter for free.

Something important

We utilize the Code Interpreter API project, which is freely available and open-source on GitHub. The system is built upon CodeBoxes, OpenAI’s API, LangChain Agents, and incorporates various Python packages to mimic the behavior of ChatGPT’s Code Interpreter.

This solution performs admirably with small datasets at no cost. However, for larger datasets, there’s a limitation imposed by OpenAI’s rate limit for free users, hindering extensive analysis. If you intend to use it for substantial data volumes, it is advisable to link a payment method to your OpenAI account.

The project is optimized for compatibility with the GPT-4 API, and it functions smoothly. Additionally, the code customized to ensure compatibility with the GPT-3.5-turbo model as well.

Set Up codeinterpreterapi

The below command to install the Code Interpreter API.

pip install codeinterpreterapi

After that, get an API key from OpenAI’s website. Click on “Create new secret key” and copy the key.

Usage of codeinterpreterapi

Copy the below code and paste it into any code editor. The code is from the GitHub page of the Code Interpreter API with little changes.

import os
os.environ["OPENAI_API_KEY"] = "PASTE THE OPENAI API KEY HERE"

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(
"Plot the bitcoin chart of 2023 YTD"
)

# 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())

First, paste the OpenAI API key in the second line.

After that, if you have access to the GPT-4 API, you can define the “gpt-4” model in the ninth line.

Finally, in the 14th line, you can enter your query and define what you want to create and save the file as a (.py) python file.

Run the Python file.

Bitcoin YTD Chart Output

Dataset Analysis

Use any dataset to perform data analysis for free.

import os
os.environ["OPENAI_API_KEY"] = "PASTE THE OPENAI API KEY HERE"

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 = "Analyze this dataset and plot something interesting about it."
files = [
File.from_path("iris.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()


if __name__ == "__main__":
import asyncio

asyncio.run(main())

Streamlit WebApp

To start the web application created with streamlit:

streamlit run frontend/app.py

— — —

What’s a programmer’s favorite bedtime story?

The tale of CodeInterpreterAPI’s magic in simplifying code!

🙂🙂🙂

--

--