Skip to content

Commit c3c91b4

Browse files
authored
adding docs (#134)
1 parent 9dd2e82 commit c3c91b4

14 files changed

+320
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ if __name__ == "__main__":
102102
![Iris Dataset Analysis](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/iris_analysis.png?raw=true)
103103
Iris Dataset Analysis Output
104104

105+
## Docs
106+
Check out the [documentation](https://codeinterpreter.hello-cluster.com/)
107+
105108
## Production
106109

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

docs/bitcoin_chart.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Bitcoin Chart
2+
This example creates a CodeInterpreterSession and generates a response to plot the bitcoin chart for year 2023:
3+
4+
```python
5+
from codeinterpreterapi import CodeInterpreterSession
6+
7+
with CodeInterpreterSession() as session:
8+
response = session.generate_response("Plot the bitcoin chart for year 2023")
9+
10+
print(response.content)
11+
response.files[0].show_image() # Show the chart image
12+
```
13+
14+
The session handles executing the python code to generate the chart in the sandboxed environment. The response contains the chart image that can be displayed.
15+
16+
![Bitcoin Chart Output](https://raw.githubusercontent.com/shroominic/codeinterpreter-api/main/examples/assets/bitcoin_chart.png)
17+
Bitcoin Chart Output

docs/code_interpreter_response.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CodeInterpreterResponse
2+
The CodeInterpreterResponse contains the AI agent's response.
3+
4+
It contains:
5+
6+
- `content`: text response content
7+
- `files`: list of generated File attachments
8+
- `code_log`: log of executed code snippets

docs/code_interpreter_session.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# CodeInterpreterSession
2+
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.
3+
4+
Key responsibilities:
5+
6+
- Starting and stopping the compute session
7+
- Sending user input and files to the agent
8+
- Running code in the compute container
9+
- Retrieving output files and images
10+
- Managing the chat history
11+
- Logging
12+
13+
It provides methods like:
14+
15+
- `generate_response()`: Generate AI response for user input
16+
- `start() / stop()`: Start and stop the session
17+
- `log()`: Log messages
18+
- `show_code` - Callback to print code before running.
19+
20+
21+
The response generation happens through a pipeline:
22+
23+
1. User input is parsed
24+
2. Code is executed if needed
25+
3. Files are processed if needed
26+
4. Final response is formatted and returned
27+
28+
The `generate_response()` method handles this entire pipeline.
29+
30+
Usage:
31+
32+
```python
33+
from codeinterpreterapi import CodeInterpreterSession
34+
35+
with CodeInterpreterSession() as session:
36+
response = session.generate_response("Plot a histogram of the data")
37+
print(response.content) # print AI response
38+
```

docs/codebox.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# CodeBox
2+
The CodeBox class provides the isolated secure environment for executing python code. It is used by the CodeInterpreterSession internally.
3+
4+
It provides methods like:
5+
6+
- `upload() / download()`: Upload and download files
7+
- `run()`: Run python code
8+
- `install()`: Install python packages
9+
10+
The CodeBox handles setting up the environment, installing packages, running code, capturing output and making it available.
11+
12+
It uses Docker containers under the hood to provide the isolated env.
13+
14+
Usage:
15+
16+
```python
17+
from codeboxapi import CodeBox
18+
19+
codebox = CodeBox()
20+
codebox.upload("data.csv", b"1,2,3\
21+
4,5,6")
22+
output = codebox.run("import pandas as pd; df = pd.read_csv('data.csv')")
23+
print(output.content)
24+
```

docs/concepts_overview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Concepts Overview
2+
| name | description |
3+
|-|-|
4+
| CodeInterpreterSession | Main class that manages a code execution session |
5+
| CodeBox | Handles code execution in a sandboxed environment |
6+
| File | Represents a file for upload/download to CodeBox |
7+
| UserRequest | User input message with optional file attachments |
8+
| CodeInterpreterResponse | AI response message with optional files and code log |

docs/deploy.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Deployment
2+
CodeInterpreterAPI can be easily deployed to production using the CodeBox framework.
3+
4+
## Prerequisites
5+
- CodeBox API key
6+
- Get your API key from [CodeBox](https://pay.codeboxapi.com/b/00g3e6dZX2fTg0gaEE) (get 70% with the code `BETA`)
7+
- CodeInterpreterAPI installed
8+
- `pip install codeinterpreterapi`
9+
10+
## Setup
11+
12+
Set the `CODEBOX_API_KEY` environment variable or directly in your code:
13+
14+
```python
15+
from codeinterpreterapi import settings
16+
17+
settings.CODEBOX_API_KEY = "sk-..."
18+
```
19+
20+
## Starting a Session
21+
22+
To start a code interpreter session using CodeBox:
23+
24+
```python
25+
from uuid import uuid4
26+
from codeinterpreterapi import CodeInterpreterSession
27+
28+
session_id = uuid4()
29+
30+
session = CodeInterpreterSession.from_id(session_id)
31+
session.start()
32+
```
33+
34+
The `session_id` allows restoring the session later after restarting the application.
35+
36+
## Generating Responses
37+
38+
With the session started, you can now generate responses like normal:
39+
40+
```python
41+
response = session.generate_response(
42+
"Plot a histogram of the iris dataset"
43+
)
44+
45+
response.show()
46+
```
47+
48+
This will execute the code securely using CodeBox.
49+
50+
## Stopping the Session
51+
52+
Don't forget to stop the session when finished:
53+
54+
```python
55+
session.stop()
56+
```
57+
58+
This will shutdown the CodeBox instance.
59+
60+
## Next Steps
61+
62+
- See the [CodeBox docs](https://codeboxapi.com/docs) for more details on deployment options.
63+
- Look at the [examples](https://github.com/shroominic/codebox-api/tree/main/examples) for more usage ideas.
64+
- Contact [Shroominic](https://twitter.com/shroominic) for assistance with scaling.

docs/file.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# File
2+
The File class is used to represent files that are uploaded or downloaded during the session.
3+
4+
It stores the filename and binary content of the file.
5+
6+
It provides utility methods like:
7+
8+
- `from_path()`: Create File from filesystem path
9+
- `from_url` - Create File from URL
10+
- `save()`: Save File to filesystem path
11+
- `show_image()`: Display image File
12+
13+
Usage:
14+
15+
```python
16+
from codeinterpreterapi import File
17+
18+
file = File.from_path("image.png")
19+
file.show_image() # display image
20+
file.save("copy.png") # save copy
21+
```
22+
23+
File objects can be passed to `CodeInterpreterSession.generate_response` to make them available to the agent.

docs/installation.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Installation
2+
## Install Dependencies
3+
4+
To install, it's recommended to create a virtual environment (using `venv` in the example below):
5+
6+
```bash
7+
python3 -m venv codeinterpreterenv
8+
source codeinterpreterenv/bin/activate
9+
```
10+
11+
Then install the package:
12+
13+
```bash
14+
pip install "codeinterpreterapi[all]"
15+
```
16+
17+
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.
18+
19+
## Set Up Environment Variables
20+
21+
22+
You will also need to configure API keys for the AI model you want to use, either OpenAI, Anthropic, or Azure.
23+
24+
For OpenAI, create a `.env` file with:
25+
26+
```bash
27+
OPENAI_API_KEY=sk-...
28+
```
29+
or export as an environment variable in your terminal:
30+
31+
```bash
32+
export OPENAI_API_KEY=your_openai_api_key
33+
```
34+
35+
For Azure, use:
36+
37+
```bash
38+
OPENAI_API_TYPE=azure
39+
OPENAI_API_VERSION=2023-07-01-preview
40+
OPENAI_API_BASE=
41+
DEPLOYMENT_NAME=
42+
```

docs/iris_dataset.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Analyzing the Iris Dataset
2+
```python
3+
from codeinterpreterapi import CodeInterpreterSession, File
4+
5+
async def main():
6+
# context manager for auto start/stop of the session
7+
async with CodeInterpreterSession() as session:
8+
# define the user request
9+
user_request = "Analyze this dataset and plot something interesting about it."
10+
files = [
11+
File.from_path("examples/assets/iris.csv"),
12+
]
13+
14+
# generate the response
15+
response = await session.generate_response(
16+
user_request, files=files
17+
)
18+
19+
# output to the user
20+
print("AI: ", response.content)
21+
for file in response.files:
22+
file.show_image()
23+
24+
25+
if __name__ == "__main__":
26+
import asyncio
27+
28+
asyncio.run(main())
29+
```
30+
31+
![Iris Dataset Analysis](https://github.com/shroominic/codeinterpreter-api/blob/main/examples/assets/iris_analysis.png?raw=true)
32+
Iris Dataset Analysis Output

docs/streamlit_webapp.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Using the Streamlit Webapp
2+
The streamlit webapp allows interacting with the API through a GUI:
3+
4+
```bash
5+
streamlit run frontend/app.py --browser.gatherUsageStats=False
6+
```
7+
8+
This will launch the webapp where you can:
9+
10+
- Write prompts and see results immediately
11+
- Upload files that get passed to the API
12+
- Download any files produced by the API
13+
- Switch between different models like GPT-3.5 Turbo
14+
15+
So the webapp allows easily leveraging the API through a graphical interface.

docs/usage.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Usage
2+
To create a session and generate a response:
3+
4+
```python
5+
from codeinterpreterapi import CodeInterpreterSession, settings
6+
7+
# set api key (or automatically loads from env vars)
8+
settings.OPENAI_API_KEY = "sk-***************"
9+
10+
# create a session
11+
with CodeInterpreterSession() as session:
12+
# generate a response based on user input
13+
response = session.generate_response(
14+
"Plot the bitcoin chart of year 2023"
15+
)
16+
17+
# output the response
18+
response.show()
19+
```

docs/user_request.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# UserRequest
2+
The UserRequest class represents the user input to the agent.
3+
4+
It contains:
5+
6+
- `content`: text content of user message
7+
- `files`: list of File attachments
8+
9+
Usage:
10+
11+
```python
12+
from codeinterpreterapi import UserRequest, File
13+
14+
request = UserRequest(
15+
content="Here is an image",
16+
files=[File.from_path("image.png")]
17+
)
18+
```

docs/welcome.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Welcome
2+
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.
3+
4+
Some key features:
5+
6+
- Sandboxed execution of Python code snippets provided by the AI assistant using CodeBox. CodeBox is the simplest cloud infrastructure for your LLM Apps.
7+
- Automatic handling of file uploads/downloads
8+
- Support for stateful conversations with chat history
9+
- Extensible architecture to add custom tools and logic

0 commit comments

Comments
 (0)