Skip to content

Commit 784976c

Browse files
committed
Merge branch 'release/v3'
2 parents 9c9c5f3 + d4a1d0e commit 784976c

17 files changed

Lines changed: 2980 additions & 7 deletions

File tree

docs/mint.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"logo": {
44
"light": "/logo/logo.png",
55
"dark": "/logo/logo.png",
6-
"href": "https://pandas-ai.com"
6+
"href": "https://getpanda.ai"
77
},
88
"favicon": "/favicon.svg",
99
"colors": {
@@ -72,9 +72,14 @@
7272
"pages": ["v3/ai-dashboards", "v3/share-dataframes", "v3/permission-management"],
7373
"version": "v3"
7474
},
75+
{
76+
"group": "Advanced Usage",
77+
"pages": ["v3/agent"],
78+
"version": "v3"
79+
},
7580
{
7681
"group": "Backwards Compatibility",
77-
"pages": ["v3/agent", "v3/smart-dataframes", "v3/smart-datalakes"],
82+
"pages": ["v3/smart-dataframes", "v3/smart-datalakes"],
7883
"version": "v3"
7984
},
8085
{

docs/v3/agent.mdx

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
title: 'Agent'
3-
description: 'Add few-shot learning to your PandaAI agent'
2+
title: "Agent"
3+
description: "Add few-shot learning to your PandaAI agent"
44
---
55

66
<Note title="Beta Notice">
7-
Release v3 is currently in beta. This documentation reflects the features and functionality in progress and may change before the final release.
7+
Release v3 is currently in beta. This documentation reflects the features and
8+
functionality in progress and may change before the final release.
89
</Note>
910

1011
You can train PandaAI to understand your data better and to improve its performance. Training is as easy as calling the `train` method on the `Agent`.
1112

12-
1313
## Prerequisites
1414

15-
Before you start training PandaAI, you need to set your PandaAI API key.
15+
Before you start training PandaAI, you need to set your PandaAI API key.
1616
You can generate your API key by signing up at [https://app.pandabi.ai](https://app.pandabi.ai).
1717

1818
```python
@@ -134,6 +134,60 @@ print(response)
134134
# The model will use the information provided in the training to generate a response
135135
```
136136

137+
## Using the Sandbox Environment
138+
139+
To enhance security and protect against malicious code through prompt injection, PandaAI provides a sandbox environment for code execution. The sandbox runs your code in an isolated Docker container, ensuring that potentially harmful operations are contained.
140+
141+
### Installation
142+
143+
Before using the sandbox, you need to install Docker on your machine and ensure it is running.
144+
145+
First, install the sandbox package:
146+
147+
```bash
148+
pip install pandasai-docker
149+
```
150+
151+
### Basic Usage
152+
153+
Here's how to use the sandbox with your PandaAI agent:
154+
155+
```python
156+
from pandasai import Agent
157+
from pandasai_docker import DockerSandbox
158+
159+
# Initialize the sandbox
160+
sandbox = DockerSandbox()
161+
sandbox.start()
162+
163+
# Create an agent with the sandbox
164+
df = pai.read_csv("data.csv")
165+
agent = Agent([df], sandbox=sandbox)
166+
167+
# Chat with the agent - code will run in the sandbox
168+
response = agent.chat("Calculate the average sales")
169+
170+
# Don't forget to stop the sandbox when done
171+
sandbox.stop()
172+
```
173+
174+
### Customizing the Sandbox
175+
176+
You can customize the sandbox environment by specifying a custom name and Dockerfile:
177+
178+
```python
179+
sandbox = DockerSandbox(
180+
"custom-sandbox-name",
181+
"/path/to/custom/Dockerfile"
182+
)
183+
```
184+
185+
<Note>
186+
The sandbox works offline and provides an additional layer of security for
187+
code execution. It's particularly useful when working with untrusted data or
188+
when you need to ensure that code execution is isolated from your main system.
189+
</Note>
190+
137191
## Troubleshooting
138192

139193
In some cases, you might get an error like this: `No vector store provided. Please provide a vector store to train the agent`. It means no API key has been generated to use the `BambooVectorStore`.
@@ -153,9 +207,11 @@ vector_store = BambooVectorStor(api_key="YOUR_PANDABI_API_KEY")
153207
# Instantiate the agent with the custom vector store
154208
agent = Agent(connector, config={...} vectorstore=vector_store)
155209
```
210+
156211
## Custom Head
157212

158213
In some cases, you might want to provide custom data samples to the conversational agent to improve its understanding and responses. For example, you might want to:
214+
159215
- Provide better examples that represent your data patterns
160216
- Avoid sharing sensitive information
161217
- Guide the agent with specific data scenarios

examples/docker_sandbox.ipynb

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Execute code in a sandbox\n",
8+
"\n",
9+
"To enhance security and protect yourself from malicious code through prompt injection, \n",
10+
"we make it possible to run code in a sandbox environment.\n",
11+
"This notebook explains how to do it."
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"## Install the package\n",
19+
"\n",
20+
"First of all you need to install the python package. You can use pip to install it"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"%pip install pandasai-docker"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Execute the code in the sandbox with the agent\n",
37+
"\n",
38+
"Please keep in mind the sandbox works offline. \n",
39+
"Once you have installed the package, you can start the sandbox with the following code.\n",
40+
"For the purpose of this example, we are going to use bambooLLM as the LLM chosen for the agent."
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"import pandasai as pai\n",
50+
"from pandasai import Agent\n",
51+
"from pandasai_docker import DockerSandbox\n",
52+
"\n",
53+
"pai.set_api_key(\"YOUR_API_KEY\")\n",
54+
"\n",
55+
"# initialize the sandbox\n",
56+
"sandbox = DockerSandbox()\n",
57+
"sandbox.start()\n",
58+
"\n",
59+
"# read a csv as df\n",
60+
"df = pai.read_csv(\"./data/heart.csv\")\n",
61+
"\n",
62+
"# pass the csv and the sandbox to the agent\n",
63+
"agent = Agent([df], memory_size=10, sandbox=sandbox)\n",
64+
"\n",
65+
"# Chat with the Agent\n",
66+
"response = agent.chat(\"plot top five artists streams\")\n",
67+
"\n",
68+
"# stop the sandbox (docker container)\n",
69+
"sandbox.stop()"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"## Customize the sandbox\n",
77+
"\n",
78+
"You can decide the name and path of your sandbox by passing them as positional arguments in the DockerSandbox()"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"metadata": {},
85+
"outputs": [],
86+
"source": [
87+
"sandbox = DockerSandbox(\"pandaai-sandbox\", \"/path/to/Dockerfile\")\n",
88+
"\n",
89+
"# read a csv as df\n",
90+
"df = pai.read_csv(\"./data/heart.csv\")\n",
91+
"\n",
92+
"# pass the csv and the sandbox to the agent\n",
93+
"agent = Agent([df], memory_size=10, sandbox=sandbox)\n",
94+
"\n",
95+
"# Chat with the Agent\n",
96+
"response = agent.chat(\"plot top five artists streams\")\n",
97+
"\n",
98+
"sandbox.stop()"
99+
]
100+
}
101+
],
102+
"metadata": {
103+
"kernelspec": {
104+
"display_name": "Python 3",
105+
"language": "python",
106+
"name": "python3"
107+
},
108+
"language_info": {
109+
"codemirror_mode": {
110+
"name": "ipython",
111+
"version": 3
112+
},
113+
"file_extension": ".py",
114+
"mimetype": "text/x-python",
115+
"name": "python",
116+
"nbconvert_exporter": "python",
117+
"pygments_lexer": "ipython3",
118+
"version": "3.8.0"
119+
}
120+
},
121+
"nbformat": 4,
122+
"nbformat_minor": 4
123+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Docker Sandbox Extension for PandasAI
2+
3+
## Installation
4+
5+
You can install this extension using poetry:
6+
7+
```bash
8+
poetry add pandasai-docker
9+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.9
2+
3+
LABEL image_name="pandasai-sandbox"
4+
5+
# Install required Python packages
6+
RUN pip install pandas numpy matplotlib
7+
8+
# Set the working directory inside the container
9+
WORKDIR /app
10+
11+
# Default command keeps the container running (useful for testing or debugging)
12+
CMD ["sleep", "infinity"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .docker_sandbox import DockerSandbox
2+
3+
__all__ = ["DockerSandbox"]

0 commit comments

Comments
 (0)