Skip to main content

CodeInterpreterAPI is an (unofficial) open source python interface for the ChatGPT CodeInterpreter.

Project description

Code Interpreter API

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.

Features

  • Dataset Analysis, Stock Charting, Image Manipulation, ....
  • Internet access and auto Python package installation
  • Input text + files -> Receive text + files
  • Conversation Memory: respond based on previous inputs
  • Run everything local except the OpenAI API (OpenOrca or others maybe soon)
  • Use CodeBox API for easy scaling in production (coming soon)

Installation

Get your OpenAI API Key here and install the package.

pip install "codeinterpreterapi[all]"

Everything for local experiments are installed with the all extra. For deployments, you can use pip install codeinterpreterapi instead which does not install the additional dependencies.

Usage

Make sure to set the OPENAI_API_KEY environment variable (or use a .env file)

from codeinterpreterapi import CodeInterpreterSession


async def main():
    # create a session
    session = CodeInterpreterSession()
    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())

Bitcoin YTD
Bitcoin YTD Chart Output

Dataset Analysis

from codeinterpreterapi import CodeInterpreterSession, File


async def main():
    # context manager for auto start/stop of the session
    async with CodeInterpreterSession() as session:
        # define the user request
        user_request = "Analyze this dataset and plot something interesting about it."
        files = [
            File.from_path("examples/assets/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())

Iris Dataset Analysis
Iris Dataset Analysis Output

Production

In case you want to deploy to production, you can utilize the CodeBox API for seamless scalability.

Please contact me if you are interested in this, as it is still in the early stages of development.

Contributing

There are some remaining TODOs in the code. So, if you want to contribute, feel free to do so. You can also suggest new features. Code refactoring is also welcome. Just open an issue or pull request and I will review it.

Please also submit any bugs you find as an issue with a minimal code example or screenshot. This helps me a lot in improving the code.

Thanks!

Streamlit WebApp

To start the web application created with streamlit:

streamlit run frontend/app.py

License

MIT

Contact

You can contact me at contact@shroominic.com. But I prefer to use Twitter or Discord DMs.

Support this project

If you would like to help this project with a donation, you can click here. Thanks, this helps a lot! ❤️

Star History

Star History Chart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt_code_interpreter-0.0.2.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

gpt_code_interpreter-0.0.2-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file gpt_code_interpreter-0.0.2.tar.gz.

File metadata

  • Download URL: gpt_code_interpreter-0.0.2.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for gpt_code_interpreter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b1bde58d1628491f58db3c40c20ec9eb1c31c0b19b129d50aca9f9a1dd59bc0c
MD5 e3c53d627d7496ae612367dff193d810
BLAKE2b-256 0161020c8395f8bd80a8d766bf711acfe9729371d9e380d84296fb86139aadcc

See more details on using hashes here.

File details

Details for the file gpt_code_interpreter-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gpt_code_interpreter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 16502b17ae1bb9e6cd757e810a95be7293445569549cb0237664565930cf69b3
MD5 734ea7afb4ddba381c1fd3593138c4d6
BLAKE2b-256 30dc8bb450a79e474dc84009b370014b18c6a91ce5faeb27e79848e6702a6428

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page