Prompts
This module includes some methods on optimally handling prompts when interacting with LLMs.
Base Prompt
A base prompt
pandasai.prompts.base
Base class to implement a new Prompt In order to better handle the instructions, this prompt module is written.
Prompt
Base class to implement a new Prompt
Source code in pandasai/prompts/base.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
__init__(**kwargs)
init method of Base class of Prompt Module
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs |
Inferred Keyword Arguments |
{}
|
Source code in pandasai/prompts/base.py
16 17 18 19 20 21 22 23 24 | |
Generate Python Code
A standard prompt is designed to be used when querying the LLMs to generate Python Code.
pandasai.prompts.generate_python_code
Prompt to generate Python code
Today is {today_date}.
You are provided with a pandas dataframe (df) with {num_rows} rows and {num_columns} columns.
This is the result of `print(df.head({rows_to_display}))`:
{df_head}.
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 {START_CODE_TAG} exactly and suffix the code with {END_CODE_TAG}
exactly to get the answer to the following question:
GeneratePythonCodePrompt
Bases: Prompt
Prompt to generate Python code
Source code in pandasai/prompts/generate_python_code.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Generate Python Code On Error
A prompt to generate Python Code on Error
pandasai.prompts.correct_error_prompt
Prompt to correct Python Code on Error
Today is {today_date}.
You are provided with a pandas dataframe (df) with {num_rows} rows and {num_columns} columns.
This is the result of `print(df.head({rows_to_display}))`:
{df_head}.
The user asked the following question:
{question}
You generated this python code:
{code}
It fails with the following error:
{error_returned}
Correct the python code and return a new python code (do not import anything) that fixes the above
mentioned error. Do not generate the same code again. Make sure to prefix the requested python
code with {START_CODE_TAG} exactly and suffix the code with {END_CODE_TAG} exactly.
CorrectErrorPrompt
Bases: Prompt
Prompt to Correct Python code on Error
Source code in pandasai/prompts/correct_error_prompt.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
Generate Response
A prompt to generate Conversational Response
pandasai.prompts.generate_response
Prompt to generate the response to the question in a conversational way
Question: {question}
Answer: {answer}
Rewrite the answer to the question in a conversational way.
GenerateResponsePrompt
Bases: Prompt
Prompt to generate the response to the question in a conversational way
Source code in pandasai/prompts/generate_response.py
14 15 16 17 18 19 20 21 22 23 | |
Generate Python Code Multiple DataFrames
A standard prompt is designed to be used when querying the LLMs to generate Python Code.
pandasai.prompts.multiple_dataframes
Prompt to generate Python code for multiple dataframes
MultipleDataframesPrompt
Bases: Prompt
Prompt to generate Python code
Source code in pandasai/prompts/multiple_dataframes.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
Generate Python Code On Error Multiple DataFrames
A prompt to generate Python Code on Error
pandasai.prompts.correct_multiples_prompt
Prompt to correct error
CorrectMultipleDataframesErrorPrompt
Bases: Prompt
Prompt to generate Python code
Source code in pandasai/prompts/correct_multiples_prompt.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |