Skip to content

shroominic/codeinterpreter-api

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
July 17, 2023 15:56
July 14, 2023 14:06
July 14, 2023 13:25
July 14, 2023 14:03
July 14, 2023 14:06
July 10, 2023 02:20

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

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
    output = await session.generate_response(
        "Plot the bitcoin chart of 2023 YTD"
    )

    # ouput 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 use the CodeBox API for easy scaling.

Please contact me if you interested in this, because it's still in early development.

Contributing

There are some TODOs left 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.

Also please submit any bugs you find as an issue with a minimal code example or screenshot. This helps me a lot to improve the code.

Thanks!

License

MIT

Contact

You can contact me at [email protected]. But I prefer to use Twitter or Discord DMs.

Support this project

If you want to help this project with a donation you can click here. Thanks this helps alot! ❤️

Star History

Star History Chart