Skip to content

Commit

Permalink
feat: call run via functional operator (Sinaptik-AI#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
mspronesti authored May 18, 2023
1 parent ef82b0f commit 1a5cd39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ from pandasai.llm.openai import OpenAI
llm = OpenAI(api_token="YOUR_API_TOKEN")

pandas_ai = PandasAI(llm, conversational=False)
pandas_ai.run(df, prompt='Which are the 5 happiest countries?')
pandas_ai(df, prompt='Which are the 5 happiest countries?')
```

The above code will return the following:
Expand All @@ -64,7 +64,7 @@ Name: country, dtype: object
Of course, you can also ask PandasAI to perform more complex queries. For example, you can ask PandasAI to find the sum of the GDPs of the 2 unhappiest countries:

```python
pandas_ai.run(df, prompt='What is the sum of the GDPs of the 2 unhappiest countries?')
pandas_ai(df, prompt='What is the sum of the GDPs of the 2 unhappiest countries?')
```

The above code will return the following:
Expand All @@ -76,7 +76,7 @@ The above code will return the following:
You can also ask PandasAI to draw a graph:

```python
pandas_ai.run(
pandas_ai(
df,
"Plot the histogram of countries showing for each the gpd, using different colors for each bar",
)
Expand Down
19 changes: 19 additions & 0 deletions pandasai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ def run(
self.log(f"Conversational answer: {answer}")
return answer

def __call__(
self,
data_frame: pd.DataFrame,
prompt: str,
is_conversational_answer: bool = None,
show_code: bool = False,
anonymize_df: bool = True,
use_error_correction_framework: bool = True,
) -> str:
"""Run the LLM with the given prompt"""
return self.run(
data_frame,
prompt,
is_conversational_answer,
show_code,
anonymize_df,
use_error_correction_framework
)

def remove_unsafe_imports(self, code: str) -> str:
"""Remove non-whitelisted imports from the code to prevent malicious code execution"""

Expand Down

0 comments on commit 1a5cd39

Please sign in to comment.