Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/v3/agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,46 @@ smart_df = pai.SmartDataframe(df, config={
```

The agent will use your custom head instead of the default first 5 rows of the dataframe when analyzing and responding to queries.

### Using Sandbox

To use the sandbox environment, you first need to install the required package and have Docker running on your system:

```bash
pip install pandasai-docker
```

<Note title="Sandbox Requirements">
Make sure you have Docker running on your system before using the sandbox
environment.
</Note>

Here's how to enable the sandbox for your PandaAI agent:

```python
from pandasai import Agent
from pandasai_docker import DockerSandbox

# Initialize and start the sandbox
sandbox = DockerSandbox()
sandbox.start()

# Create an agent with the sandbox enabled
agent = Agent("data.csv", sandbox=sandbox)

# The code will now run in an isolated Docker container
response = agent.chat("What is the total sales for each country?")

# Don't forget to stop the sandbox when done
sandbox.stop()
```

You can also customize the sandbox environment:

```python
# Custom sandbox configuration
sandbox = DockerSandbox(
"custom-sandbox-name",
"/path/to/custom/Dockerfile"
)
```
6 changes: 4 additions & 2 deletions docs/v3/large-language-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ description: "Set up Large Language Model in PandaAI"
---

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

PandaAI supports multiple LLMs.
Expand Down Expand Up @@ -79,7 +80,7 @@ llm = AzureOpenAI(api_base="https://<your-endpoint>.openai.azure.com/",
pai.config.set({"llm": llm})
```

## LiteLLM
## How to set up any LLM?

LiteLLM provides a unified interface to interact with 100+ LLM models from various providers including OpenAI, Azure, Anthropic, Google, AWS, Hugging Face, and many more. This makes it easy to switch between different LLM providers without changing your code.

Expand Down Expand Up @@ -115,6 +116,7 @@ pai.config.set({"llm": llm})
```

LiteLLM supports a wide range of models from various providers, including but not limited to:

- OpenAI (gpt-3.5-turbo, gpt-4, etc.)
- Anthropic (claude-2, claude-instant-1, etc.)
- Google (gemini-pro, palm2, etc.)
Expand Down
55 changes: 19 additions & 36 deletions docs/v3/privacy-security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ description: "Understanding security implications and sandbox options in PandaAI
---

<Note title="Beta Notice">
PandaAI 3.0 is currently in beta. This documentation reflects the latest features and functionality, which may evolve before the final release.
PandaAI 3.0 is currently in beta. This documentation reflects the latest
features and functionality, which may evolve before the final release.
</Note>

## Code Execution and Sandbox Environment
Expand All @@ -27,53 +28,35 @@ To use the sandbox environment, you first need to install the required package a
```bash
pip install pandasai-docker
```

<Note title="Sandbox Requirements">
Make sure you have Docker running on your system before using the sandbox environment.
Make sure you have Docker running on your system before using the sandbox
environment.
</Note>

Here's how to enable the sandbox for your PandaAI agent:
Here's how to enable the sandbox for your PandaAI chat:

```python
from pandasai import Agent
```
import pandasai as pai
from pandasai_docker import DockerSandbox

# Initialize and start the sandbox
pai.api_key.set("YOUR_API_KEY")

# initialize the sandbox
sandbox = DockerSandbox()
sandbox.start()

# Create an agent with the sandbox enabled
agent = Agent("data.csv", sandbox=sandbox)
# read a csv as df
df = pai.read_csv("./data/heart.csv")

# The code will now run in an isolated Docker container
response = agent.chat("What is the total sales for each country?")
# pass the df and the sandbox
result = pai.chat("plot total heart patients by gender", df, sandbox=sandbox)

# Don't forget to stop the sandbox when done
sandbox.stop()
```

You can also customize the sandbox environment:
# display the chart
result.show()

```python
# Custom sandbox configuration
sandbox = DockerSandbox(
"custom-sandbox-name",
"/path/to/custom/Dockerfile"
)
```

For additional security in production environments, you can combine the sandbox with the Advanced Security Agent:

```python
from pandasai.ee.agents.advanced_security_agent import AdvancedSecurityAgent

# Create a security agent
security = AdvancedSecurityAgent()

# Use both sandbox and security agent
agent = Agent("data.csv", sandbox=sandbox, security=security)

# Queries will be checked for security risks and run in isolation
response = agent.chat("Calculate total sales")
# stop the sandbox (docker container)
sandbox.stop()
```

### When to Use the Sandbox
Expand Down
39 changes: 38 additions & 1 deletion examples/docker_sandbox.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@
"%pip install pandasai-docker"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Execute the code in the sandbox\n",
"\n",
"Please keep in mind the sandbox works offline. \n",
"Once you have installed the package, you can start the sandbox with the following code."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandasai as pai\n",
"from pandasai_docker import DockerSandbox\n",
"\n",
"pai.api_key.set(\"YOUR_API_KEY\")\n",
"\n",
"# initialize the sandbox\n",
"sandbox = DockerSandbox()\n",
"sandbox.start()\n",
"\n",
"# read a csv as df\n",
"df = pai.read_csv(\"./data/heart.csv\")\n",
"\n",
"# pass the csv and the sandbox to the agent\n",
"result = pai.chat(\"plot total heart patients by gender\", df, sandbox=sandbox)\n",
"\n",
"result.show()\n",
"\n",
"# stop the sandbox (docker container)\n",
"sandbox.stop()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -50,7 +87,7 @@
"from pandasai import Agent\n",
"from pandasai_docker import DockerSandbox\n",
"\n",
"pai.set_api_key(\"YOUR_API_KEY\")\n",
"pai.api_key.set(\"YOUR_API_KEY\")\n",
"\n",
"# initialize the sandbox\n",
"sandbox = DockerSandbox()\n",
Expand Down
2 changes: 1 addition & 1 deletion pandasai/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class PandaAIApiKeyError(Exception):
"""

def __init__(self, message=None):
default_message = "PandaAI API key not found. Please set your API key using PandaAI.set_api_key() or by setting the PANDASAI_API_KEY environment variable."
default_message = "PandaAI API key not found. Please set your API key using PandaAI.api_key.set() or by setting the PANDASAI_API_KEY environment variable."
super().__init__(message or default_message)


Expand Down
Loading