Skip to main content

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_hyperobjekt[all]"

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

Usage

To configure OpenAI and Azure OpenAI, ensure that you set the appropriate environment variables (or use a .env file):

For OpenAI, set the OPENAI_API_KEY environment variable:

export OPENAI_API_KEY=your_openai_api_key

For Azure OpenAI, set the following environment variables:

export OPENAI_API_TYPE=azure
export OPENAI_API_VERSION=your_api_version
export OPENAI_API_BASE=your_api_base
export OPENAI_API_KEY=your_azure_openai_api_key
export DEPLOYMENT_NAME=your_deployment_name

Remember to replace the placeholders with your actual API keys and other required information.

from codeinterpreterapi_hyperobjekt 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_hyperobjekt 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

Metadata

Release files for codeinterpreterapi-hyperobjekt 0.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codeinterpreterapi-hyperobjekt 0.0.16
File Size Uploaded
codeinterpreterapi_hyperobjekt-0.0.16.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codeinterpreterapi-hyperobjekt 0.0.16
File Interpreter ABI Platform
codeinterpreterapi_hyperobjekt-0.0.16-py3-none-any.whl Python 3 none any Details

Total release size: 41.1 kB

Release files / codeinterpreterapi_hyperobjekt-0.0.16.tar.gz

Download URL codeinterpreterapi_hyperobjekt-0.0.16.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
aa31b84ca0c299ac37d627f6f330eee0a64a6578017f06a156190b16b2777961
BLAKE2b-256 checksum
How to use checksums
6cd91dcad42fcc2e43596460145bf78c8b8747481d023a5d71815a8e328a8ceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / codeinterpreterapi_hyperobjekt-0.0.16-py3-none-any.whl

Download URL codeinterpreterapi_hyperobjekt-0.0.16-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4c3f0efdc3a5d02c6c33aef9efe59305fa3c2690356aabc5d636cdb4ad9b3e6
BLAKE2b-256 checksum
How to use checksums
dee9ec68259adb1999a3906c926ad0f0d3a23da0fea62e0c85b4ecb47390f9ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.16 This release

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page