en programming language golang golang flow control How to use ChatGPT code interpreter for free (2024)

How to use ChatGPT code interpreter for free (2024)

Recently, OpenAI released a code interpreter for ChatGPT for all paid users. However, it costs $20 per month, so it’s not affordable for everyone. So, if you want to use ChatGPT code interpreter for free, this tutorial is for you. A developer named Shroominic has developed an open source implementation of a code interpreter for ChatGPT. You can perform dataset analysis and visualize data similar to ChatGPT. With that in mind, learn how to use Code Interpreter for free.

Things to keep in mind before proceeding

1. We use the free open source code Interpreter API project on GitHub (see here ). It uses CodeBox, OpenAI’s API, LangChain agent, and multiple Python packages to act like a code interpreter for ChatGPT.

2. Free and works very well for small datasets . However, when throwing large datasets for analysis, OpenAI’s rate limits for free users hinder operations. Therefore, if you plan to use it for large amounts of data, consider adding a payment method to your OpenAI account.

3. If you have access to the GPT-4 API, your project will work fine. However, we have customized the code to be compatible with the GPT-3.5-turbo model as well.

How to use ChatGPT code interpreter for free (2024)
How to use ChatGPT code interpreter for free (2024)

Step 1: Set up the code interpreter API

1. First, you need to install Python and Pip on your computer. Please follow the linked tutorial for this. Make sure to add python.exe to your PATH during installation.

2. Once you have installed Python with Pip, open a terminal and run the following command to check if it is configured correctly . The command should return output that includes a version number.

 python --version
pip --version

3. Next, run the following command to install the Code Interpreter API .

 pip install "codeinterpreterapi[all]" 

4. Then obtain your API key from the OpenAI website . Click “Create new private key” and copy the key.

How to use ChatGPT code interpreter for free (2024)
How to use ChatGPT code interpreter for free (2024)

Step 2: Run ChatGPT code interpreter for free

1. Once that’s done, run the Code Interpreter API for free.

2. Open a code editor such as Sublime Text or Notepad++ ( download ).

3. Next, copy and paste the code below into your code editor. The code is from the Code Interpreter APIGitHub page, but I’ve made some changes to avoid some errors.

 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 Apple stock price chart from 2007 to 2023 june"
    )

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

4. I have highlighted in red the code that requires some changes. First, paste your OpenAI API key on the second line .

5. Then, if you have access to the GPT-4 API, you can define the “gpt-4” model on line 9. Finally, on line 14 you can enter a query and define what you want to create.

6. Now save the file to your desktop as “chart.py”. Be sure to add the .py extension at the end.

7. Next, open a terminal and run the following commands one by one. The first command takes you to the desktop location and the second command uses Python to run the “chart.py” file.

 cd Desktop
python chart.py

8. Wait a few seconds and the Code Interpreter API will generate the graph .

9. To achieve this result, we use a number of services in the background, including the LangChain agent, Yahoo Finance data from the internet, and Matplotlib to plot the graphs. You can see everything happening in the background by adding the following lines to your code.

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

10. From now on, you can generate a new chart by simply changing the query in your code and running the “chart.py” file again.

How to use ChatGPT code interpreter for free (2024)
How to use ChatGPT code interpreter for free (2024)

Step 3: Perform data analysis using the Code Interpreter API

1. You can also perform data analysis for free using local data. To do this, create a folder on your desktop called “analysis” .

2. Now move the dataset to the Analysis folder. Datasets can be in CSV, XSL, or XSLX format. For example, use the “globaltemperture.csv” file in the “analysis” folder.

3. Next, open the code editor and paste the code below .

 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 global temperature from the year 1950 to 2016. Consider the GCAG system."
        files = [
            File.from_path("globaltemperature.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()) 

4. Here you first need to paste your OpenAI API key .

5. Now change “globaltemperture.csv” to your own dataset name. By the way, you can also change the model and user queries depending on what you want from the data.

6. Save it as “data.py” in the “analysis” folder on your desktop.

7. Launch a terminal and run the file in a similar manner.

 cd Desktop/analysis
python data.py

8. You now have a graph based on your local dataset . Here’s how you can use the Code Interpreter API to perform dataset analysis without paying.

How to use ChatGPT code interpreter for free (2024)
How to use ChatGPT code interpreter for free (2024)