Skip to content

Commit

Permalink
feat: reduce query token consumption (#270)
Browse files Browse the repository at this point in the history
* Update __init__.py

Converted the dataframe to json for lower token usage.

* test: fix tests

---------

Co-authored-by: Gabriele Venturi <[email protected]>
  • Loading branch information
soumya1729 and gventuri authored Jun 25, 2023
1 parent a09101f commit 09a41f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions pandasai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def run(
df_head = data_frame.head(rows_to_display)
if anonymize_df:
df_head = anonymize_dataframe_head(df_head)
df_head=df_head.to_csv(index=False)

generate_code_instruction = self._non_default_prompts.get(
"generate_python_code", GeneratePythonCodePrompt
Expand Down
18 changes: 10 additions & 8 deletions tests/test_pandasai.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ def test_run_with_privacy_enforcement(self, pandasai):
Today is {date.today()}.
You are provided with a pandas dataframe (df) with 3 rows and 1 columns.
This is the metadata of the dataframe:
Empty DataFrame
Columns: [country]
Index: [].
country
.
When asked about the data, your response should include a python code that describes the dataframe `df`.
Using the provided dataframe, df, return the python code and make sure to prefix the requested python code with <startCode> exactly and suffix the code with <endCode> exactly to get the answer to the following question:
Expand Down Expand Up @@ -246,10 +245,11 @@ def test_run_without_privacy_enforcement(self, pandasai):
Today is {date.today()}.
You are provided with a pandas dataframe (df) with 3 rows and 1 columns.
This is the metadata of the dataframe:
country
0 United States
1 United Kingdom
2 France.
country
United States
United Kingdom
France
.
When asked about the data, your response should include a python code that describes the dataframe `df`.
Using the provided dataframe, df, return the python code and make sure to prefix the requested python code with <startCode> exactly and suffix the code with <endCode> exactly to get the answer to the following question:
Expand Down Expand Up @@ -663,7 +663,9 @@ def test_replace_generate_code_prompt(self, llm):
expected_last_prompt = (
str(
replacement_prompt(
num_rows=df.shape[0], num_columns=df.shape[1], df_head=df.head()
num_rows=df.shape[0],
num_columns=df.shape[1],
df_head=df.head().to_csv(index=False),
)
)
+ question
Expand Down

0 comments on commit 09a41f0

Please sign in to comment.