Skip to content

Commit d701170

Browse files
committed
fixed a defect in the sandbox
1 parent 7a0d8a2 commit d701170

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,22 @@ data = [('John Doe', 25, 50),
5252
('Olivia Jackson', 29, 55)]
5353
df = pd.DataFrame(data, columns=['name', 'age', 'donation'])
5454

55-
conv_df = PandasLLM(data=df, llm_api_key = os.environ.get("OPENAI_API_KEY"), verbose=True)
56-
result = conv_df.prompt("What is the average donation of people older than 30 who donated more than $50?")
55+
conv_df = PandasLLM(data=df, llm_api_key = os.environ.get("OPENAI_API_KEY"))
56+
result = conv_df.prompt("What is the average donation of people older than 40 who donated more than $50?")
57+
code = conv_df.code_block
58+
59+
print(f"Executing the following expression of type {type(result)}:\n{code}\n\nResult is:\n {result}\n")
60+
# Executing the following expression of type <class 'numpy.float64'>:
61+
# result = df.loc[(df['age'] > 40) & (df['donation'] > 50), 'donation'].mean()
62+
63+
# Result is:
64+
# 72.5
5765

58-
print(f"Result ({type(result)}):\n {result}")
59-
# Result (<class 'numpy.float64'>):
60-
# 75.0
6166
```
6267

68+
There is also a chatbot available in the repository using the same dataset.
69+
Look at example-chatbot.py
70+
6371
## Contributing
6472
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
6573

pandas_llm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def prompt(self, request: str):
333333
for cleaned_code in results:
334334

335335
try:
336-
result = self.execInSandbox(self, cleaned_code)
336+
result = self._execInSandbox(self, cleaned_code)
337337
except Exception as e:
338338
self._print(f"error {e}")
339339
if not self.force_sandbox:

pandas_llm/example-chatbot.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@
4949

5050
def main():
5151

52-
# Set the OpenAI API key
53-
openai_key = os.environ.get("OPENAI_API_KEY")
54-
if openai_key is None:
55-
print("No OpenAI API key provided. Exiting.")
56-
return
57-
58-
conv_df = PandasLLM(data=df, llm_api_key = openai_key)
52+
# Initialise library and set the OpenAI API key
53+
conv_df = PandasLLM(data=df, llm_api_key = os.environ.get("OPENAI_API_KEY"))
5954
print()
6055
banner = """
6156
Welcome to the Donation Data CLI.
@@ -77,7 +72,9 @@ def main():
7772
break
7873

7974
result = conv_df.prompt(prompt)
80-
print(f"Result ({type(result)}):\n {result}")
75+
code = conv_df.code_block
76+
print(f"Executing the following expression of type {type(result)}:\n{code}\n\nResult is:\n {result}\n")
77+
8178

8279
if __name__ == "__main__":
8380
main()

pandas_llm/example.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
('Olivia Jackson', 29, 55)]
2222
df = pd.DataFrame(data, columns=['name', 'age', 'donation'])
2323

24-
conv_df = PandasLLM(data=df, llm_api_key = os.environ.get("OPENAI_API_KEY"), verbose=True)
25-
result = conv_df.prompt("What is the average donation of people older than 30 who donated more than $50?")
24+
conv_df = PandasLLM(data=df, llm_api_key = os.environ.get("OPENAI_API_KEY"))
25+
result = conv_df.prompt("What is the average donation of people older than 40 who donated more than $50?")
26+
code = conv_df.code_block
2627

27-
print(f"Result ({type(result)}):\n {result}")
28-
# Result (<class 'numpy.float64'>):
29-
# 75.0
28+
print(f"Executing the following expression of type {type(result)}:\n{code}\n\nResult is:\n {result}\n")
29+
# Executing the following expression of type <class 'numpy.float64'>:
30+
# result = df.loc[(df['age'] > 40) & (df['donation'] > 50), 'donation'].mean()
31+
32+
# Result is:
33+
# 72.5

0 commit comments

Comments
 (0)