Open pesmeriz opened 2 months ago
To prevent sensitive data from being shared when setting the PANDASAI_API_KEY
environment variable, you can store the API key in a .env
file and use a library like python-dotenv
to load it. This way, the API key is not hardcoded in your script.
Here is an example of how you can do this:
Install the python-dotenv
library if you haven't already:
pip install python-dotenv
Create a .env
file in your project directory and add your API key to it:
PANDASAI_API_KEY=YOUR_API_KEY
Modify your script to load the environment variables from the .env
file:
import os
from dotenv import load_dotenv
from pandasai import SmartDataframe, Agent
from pandasai.llm.local_llm import LocalLLM
from pandasai.llm import BambooLLM
import pandas as pd
# Load environment variables from .env file
load_dotenv()
local = False
bypass = False
if local:
llm = LocalLLM(api_base="http://localhost:11434/v1", model="qwen2.5-coder:latest")
else:
if bypass:
llm = BambooLLM(api_key=os.getenv("BAMBOO_API_KEY"))
else:
os.environ["PANDASAI_API_KEY"] = os.getenv("BAMBOO_API_KEY")
llm = BambooLLM()
# Your existing DataFrame and SmartDataframe setup code here
agent = Agent(
[country, employee, department],
config={
"llm": llm,
"verbose": True,
"enforce_privacy": True,
"enable_cache": False,
},
)
response = agent.chat(
"show me the employees with a salary above 80k and their respective salary"
)
print(response)
By using this approach, you ensure that the sensitive API key is not exposed in your codebase [1].
Additionally, to disable logging entirely, you can set the save_logs
option to False
in your configuration:
config = {
"save_logs": False
}
employee = SmartDataframe(
pd.DataFrame(
[
[1, "John Dow", 60000, 1],
[2, "Jane Smith", 120000, 2],
[3, "Taro Yamada", 90000, 3],
[4, "Maria Silva", 75000, 4],
[5, "Michal Johnson", 95000, 2],
],
columns=["id", "name", "salary", "department_id"],
),
custom_head=employee_head,
config={"custom_head": employee_head, "llm": llm, "enable_cache": False, "enforce_privacy": True, "save_logs": False},
)
This will disable logging for the SmartDataframe
instance by ensuring that no log files are created [2].
To continue talking to Dosu, mention @dosu.
Again, this doesn't work. I would urge the maintainers of this app to please review the support they are providing to the issues presented. A lot of them have several months with no response or with bad instruction generation by a bot.There are several bugs affecting data sharing which, without the proper disclore on the docs, might lead to potential problems especially on the EU. @dosu please tag the maintainers of this lib to this.
This is a tough nut to crack, could really use your help on this, @gventuri.
To continue talking to Dosu, mention @dosu.
System Info
OS version: MacOS Sequoia 15.0
My pyproject.toml
🐛 Describe the bug
If you set the
PANDASAI_API_KEY
on the environment variables, the logs will be published into the server you are using, potentially leading to sharing sensitive data.Follow the
log_data
variable onpublish()
in/pandasai/helpers/query_exec_tracker.py