diff --git a/docs/bitcoin_chart.md b/docs/bitcoin_chart.md index b24bd873..670ff258 100644 --- a/docs/bitcoin_chart.md +++ b/docs/bitcoin_chart.md @@ -1,4 +1,5 @@ # Bitcoin Chart + This example creates a CodeInterpreterSession and generates a response to plot the bitcoin chart for year 2023: ```python diff --git a/docs/code_interpreter_response.md b/docs/code_interpreter_response.md index d3c171d2..b92643ce 100644 --- a/docs/code_interpreter_response.md +++ b/docs/code_interpreter_response.md @@ -1,4 +1,5 @@ # CodeInterpreterResponse + The CodeInterpreterResponse contains the AI agent's response. It contains: diff --git a/docs/code_interpreter_session.md b/docs/code_interpreter_session.md index 38c3517e..fceeaa03 100644 --- a/docs/code_interpreter_session.md +++ b/docs/code_interpreter_session.md @@ -1,4 +1,5 @@ # CodeInterpreterSession + The CodeInterpreterSession is the main class that manages a conversational session between the user and AI agent. It handles starting, stopping and checking status of the secure isolated code execution environment. Key responsibilities: @@ -17,7 +18,6 @@ It provides methods like: - `log()`: Log messages - `show_code` - Callback to print code before running. - The response generation happens through a pipeline: 1. User input is parsed diff --git a/docs/codebox.md b/docs/codebox.md index 3dd152de..bd6b3e53 100644 --- a/docs/codebox.md +++ b/docs/codebox.md @@ -1,4 +1,5 @@ # CodeBox + The CodeBox class provides the isolated secure environment for executing python code. It is used by the CodeInterpreterSession internally. It provides methods like: diff --git a/docs/concepts_overview.md b/docs/concepts_overview.md index 85187121..cc301651 100644 --- a/docs/concepts_overview.md +++ b/docs/concepts_overview.md @@ -1,4 +1,5 @@ # Concepts Overview + | name | description | |-|-| | CodeInterpreterSession | Main class that manages a code execution session | diff --git a/docs/deploy.md b/docs/deploy.md index 6b3ae426..e49e53a7 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -1,9 +1,11 @@ # Deployment + CodeInterpreterAPI can be easily deployed to production using the CodeBox framework. ## Prerequisites + - CodeBox API key - - Get your API key from [CodeBox](https://pay.codeboxapi.com/b/00g3e6dZX2fTg0gaEE) (get 70% with the code `BETA`) + - Get your API key from [CodeBox](https://pay.codeboxapi.com/b/00g3e6dZX2fTg0gaEE) (you get an email with the api-key) - CodeInterpreterAPI installed - `pip install codeinterpreterapi` @@ -17,36 +19,6 @@ from codeinterpreterapi import settings settings.CODEBOX_API_KEY = "sk-..." ``` -## Starting a Session - -To start a code interpreter session using CodeBox: - -```python -from uuid import uuid4 -from codeinterpreterapi import CodeInterpreterSession - -session_id = uuid4() - -session = CodeInterpreterSession.from_id(session_id) -session.start() -``` - -The `session_id` allows restoring the session later after restarting the application. - -## Generating Responses - -With the session started, you can now generate responses like normal: - -```python -response = session.generate_response( - "Plot a histogram of the iris dataset" -) - -response.show() -``` - -This will execute the code securely using CodeBox. - ## Stopping the Session Don't forget to stop the session when finished: @@ -61,4 +33,4 @@ This will shutdown the CodeBox instance. - See the [CodeBox docs](https://codeboxapi.com/docs) for more details on deployment options. - Look at the [examples](https://github.com/shroominic/codebox-api/tree/main/examples) for more usage ideas. -- Contact [Shroominic](https://twitter.com/shroominic) for assistance with scaling. +- Contact [Shroominic](https://twitter.com/shroominic) for assistance with deployment. diff --git a/docs/file.md b/docs/file.md index 43800645..89229e11 100644 --- a/docs/file.md +++ b/docs/file.md @@ -1,4 +1,5 @@ -# File +# File Object + The File class is used to represent files that are uploaded or downloaded during the session. It stores the filename and binary content of the file. diff --git a/docs/index.md b/docs/index.md index 49d5a98a..80270e0d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,31 +1,10 @@ -# CodeInterpreterAPI Documentation +# Welcome -CodeInterpreterAPI is a Python-based API designed give LLM Agents access to python and execute code. It provides a session-based conversational chat interface and the agent framework with a tool for executing code in a secure and isolated environment. +This project provides a LangChain implementation of the ChatGPT Code Interpreter. It allows you to have a back and forth chat with the AI assistant to get it to help with programming tasks, data analysis, and more. You can run everything local except the LLM using your own OpenAI API Key. -## Key Classes +Some key features: -### CodeInterpreterSession - -This is the main class that manages a code execution session. It provides methods to start, stop, and check the status of the session. It also handles logging and file uploads for the session. - -#### Methods - -* `from_id(session_id: UUID, **kwargs) -> "CodeInterpreterSession"`: This class method creates a new session from a given UUID. -* `start() -> SessionStatus`: This method starts the session. -* `stop() -> SessionStatus`: This method stops the session. -* `log(msg: str) -> None`: This method logs a message. - -### CodeBox - -This class represents the code execution environment. It provides methods to upload files, execute code, and check the status of the execution. For more information look into the codebox api documentation. - -## Usage - -To use this API, create a new `CodeInterpreterSession` and use the `start` method to start the session. You can then use the `generate_response_sync` method to generate an AI response and the `stop` method to stop the session. You can use the generate response method multiple times in a single session to have a conversation with the AI. - -## Contributing - -Contributions are welcome. Please make sure to write functional Python with full type hinting and only write needed and precise comments. - -(This file was half chatgpt generated and not complete - real docs coming soon!) -TODO: Write real docs +- Sandboxed execution of Python code snippets provided by the AI assistant using CodeBox. CodeBox is the simplest cloud infrastructure for your LLM Apps. +- Automatic handling of file uploads/downloads +- Support for stateful conversations with chat history +- Extensible architecture to add custom tools and logic diff --git a/docs/installation.md b/docs/installation.md index 299ff245..3c9a516b 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,14 +1,6 @@ # Installation -## Install Dependencies -To install, it's recommended to create a virtual environment (using `venv` in the example below): - -```bash -python3 -m venv codeinterpreterenv -source codeinterpreterenv/bin/activate -``` - -Then install the package: +Install the package: ```bash pip install "codeinterpreterapi[all]" @@ -18,18 +10,18 @@ Everything for local experiments are installed with the all extra. For deploymen ## Set Up Environment Variables - You will also need to configure API keys for the AI model you want to use, either OpenAI, Anthropic, or Azure. For OpenAI, create a `.env` file with: ```bash -OPENAI_API_KEY=sk-... +OPENAI_API_KEY=sk-********** ``` -or export as an environment variable in your terminal: + +or export as an environment variable in your terminal before running your code: ```bash -export OPENAI_API_KEY=your_openai_api_key +export OPENAI_API_KEY=sk-********** ``` For Azure, use: diff --git a/docs/iris_dataset.md b/docs/iris_dataset.md index 7643d54f..0a4673e3 100644 --- a/docs/iris_dataset.md +++ b/docs/iris_dataset.md @@ -1,4 +1,5 @@ # Analyzing the Iris Dataset + ```python from codeinterpreterapi import CodeInterpreterSession, File diff --git a/docs/streamlit_webapp.md b/docs/streamlit_webapp.md index 2e6a13fa..05a77e7e 100644 --- a/docs/streamlit_webapp.md +++ b/docs/streamlit_webapp.md @@ -1,4 +1,5 @@ # Using the Streamlit Webapp + The streamlit webapp allows interacting with the API through a GUI: ```bash diff --git a/docs/usage.md b/docs/usage.md index 97a32faa..70ecdaf4 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -1,4 +1,5 @@ # Usage + To create a session and generate a response: ```python diff --git a/docs/user_request.md b/docs/user_request.md index 9588e4d8..7422f73f 100644 --- a/docs/user_request.md +++ b/docs/user_request.md @@ -1,4 +1,5 @@ # UserRequest + The UserRequest class represents the user input to the agent. It contains: diff --git a/docs/welcome.md b/docs/welcome.md deleted file mode 100644 index 32de8d9e..00000000 --- a/docs/welcome.md +++ /dev/null @@ -1,9 +0,0 @@ -# Welcome -This project provides a LangChain implementation of the ChatGPT Code Interpreter. It allows you to have a back and forth chat with the AI assistant to get it to help with programming tasks, data analysis, and more. You can run everything local except the LLM using your own OpenAI API Key. - -Some key features: - -- Sandboxed execution of Python code snippets provided by the AI assistant using CodeBox. CodeBox is the simplest cloud infrastructure for your LLM Apps. -- Automatic handling of file uploads/downloads -- Support for stateful conversations with chat history -- Extensible architecture to add custom tools and logic diff --git a/mkdocs.yml b/mkdocs.yml index 14f313bf..fe34dd5f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,4 +1,27 @@ -site_name: CodeInterpreterAPI - Docs +site_name: CodeInterpreterAPI - Documentation +site_author: Shroominic +site_url: https://shroominic.github.io/codeinterpreter-api/ +repo_name: shroominic/codeinterpreter-api +repo_url: https://github.com/shroominic/codeinterpreter-api/ + +nav: + - 'Getting Started': + - 'Welcome': 'index.md' + - 'Installation': 'installation.md' + - 'Usage': 'usage.md' + - 'Code Interpreter': + - 'Overview': 'concepts_overview.md' + - 'Session': 'code_interpreter_session.md' + - 'CodeBox': 'codebox.md' + - 'File': 'file.md' + - 'Request': 'user_request.md' + - 'Response': 'code_interpreter_response.md' + - 'Deployment': 'deploy.md' + - 'Examples': + - 'Bitcoin Chart': 'bitcoin_chart.md' + - 'Iris Dataset': 'iris_dataset.md' + - 'Streamlit Webapp': 'streamlit_webapp.md' + theme: name: material palette: