-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: fix all docs snippets instantiations #825
Conversation
WalkthroughThe recent updates primarily involve standardizing the configuration of Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #825 +/- ##
=======================================
Coverage 85.11% 85.11%
=======================================
Files 88 88
Lines 3809 3809
=======================================
Hits 3242 3242
Misses 567 567 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (9)
- docs/LLMs/llms.md (2 hunks)
- docs/connectors.md (6 hunks)
- docs/custom-head.md (1 hunks)
- docs/custom-instructions.md (1 hunks)
- docs/custom-prompts.md (3 hunks)
- docs/custom-whitelisted-dependencies.md (1 hunks)
- docs/examples.md (14 hunks)
- docs/getting-started.md (5 hunks)
- docs/skills.md (1 hunks)
Additional comments: 34
docs/LLMs/llms.md (2)
58-64: The changes to the instantiation of
SmartDataframe
using theconfig
parameter as a named argument are correctly applied and consistent with the PR objectives to fix outdated or incorrect code snippets in the documentation.175-179: The update to the instantiation of
SmartDataframe
with theconfig
parameter as a named argument is correctly applied here as well, ensuring that thellm
configuration is passed correctly.docs/connectors.md (7)
41-41: The import statement correctly reflects the renaming of
DataBricksConnector
toDatabricksConnector
as per the PR objectives and the AI-generated overview.41-44: The
config
parameter is correctly passed as a named argument to thePostgreSQLConnector
, which aligns with the PR's objective to ensure that theconfig
parameter is passed as a named argument.71-74: The
config
parameter is correctly passed as a named argument to theMySQLConnector
, which aligns with the PR's objective to ensure that theconfig
parameter is passed as a named argument.101-104: The
config
parameter is correctly passed as a named argument to theSqliteConnector
, which aligns with the PR's objective to ensure that theconfig
parameter is passed as a named argument.152-155: The import statement correctly reflects the renaming of
DataBricksConnector
toDatabricksConnector
as per the PR objectives and the AI-generated overview. However, the class nameSnowFlakeConnector
should be checked for consistency with the rest of the codebase, as it does not match the expectedSnowflakeConnector
naming convention.Verification successful
The use of
SnowFlakeConnector
in thedocs/connectors.md
file is consistent with its usage across the codebase, as verified by the search results. There is no need to change the class name in the documentation based on the current naming convention in the code.* 183-183: The import statement correctly reflects the renaming of `DataBricksConnector` to `DatabricksConnector` as per the PR objectives and the AI-generated overview.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the class name `SnowFlakeConnector` is consistent across the codebase. rg 'SnowFlakeConnector' --files-with-matchesLength of output: 218
- 209-212: The
config
parameter is not used with theYahooFinanceConnector
, which is inconsistent with the PR's objective to ensure that theconfig
parameter is passed as a named argument. However, this may be due to the nature of theYahooFinanceConnector
which might not require aconfig
dictionary. It's important to verify if this is the expected usage or if it's an oversight.Verification successful
To verify if the
YahooFinanceConnector
typically requires aconfig
parameter, we should look at the constructor signature in the source code. The filepandasai/connectors/yahoo_finance.py
is likely to contain the class definition, so we'll check there first. We can useast-grep
to search for the class definition and its constructor to see if aconfig
parameter is expected.
The previous
ast-grep
command failed due to a syntax error in the pattern. It seems that the pattern was not correctly formatted forast-grep
. Let's correct the syntax and try again to find the constructor of theYahooFinanceConnector
class.
The
ast-grep
command failed again due to a syntax error. It appears that the pattern used is still not compatible withast-grep
. Since we are having difficulty withast-grep
, let's switch to a different approach to inspect the constructor of theYahooFinanceConnector
class. We can userg
(ripgrep) to search for the__init__
method within the file that defines theYahooFinanceConnector
class. We know from the previousrg
output that the class is defined inpandasai/connectors/yahoo_finance.py
.
The output from
rg
shows that the__init__
method of theYahooFinanceConnector
class is callingsuper().__init__
with a parameteryahoo_finance_config
. However, this output does not show the full signature of the__init__
method, which means we still don't have the complete information about whether aconfig
parameter is expected or not.To get the full signature, we should look at the lines around the
__init__
method call. We can adjust therg
command to include some lines of context around the match.
The new output from
rg
provides the full signature of the__init__
method for theYahooFinanceConnector
class. It shows that the constructor accepts astock_ticker
parameter and aconfig
parameter, which can be either an instance ofYahooFinanceConnectorConfig
or a dictionary. Theconfig
parameter is optional, as indicated by the default valueNone
.Given this information, the usage of
YahooFinanceConnector
in thedocs/connectors.md
file without aconfig
parameter is correct, as theconfig
parameter is not mandatory. This aligns with the PR's objective to ensure that theconfig
parameter is passed as a named argument where required, and in this case, it is not required.Therefore, the usage of
YahooFinanceConnector
without theconfig
parameter in the documentation is consistent with the class definition and does not require any changes.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify if the `YahooFinanceConnector` typically requires a `config` parameter or if this usage is correct. rg 'YahooFinanceConnector' --files-with-matchesLength of output: 233
Script:
#!/bin/bash # Search for the constructor of the YahooFinanceConnector class to see if it includes a `config` parameter. ast-grep --lang python --pattern $'class YahooFinanceConnector($_) { def __init__($$$) { $$$ } }'Length of output: 598
Script:
#!/bin/bash # Correct the syntax and search for the constructor of the YahooFinanceConnector class to see if it includes a `config` parameter. ast-grep --lang python --pattern $'class YahooFinanceConnector { def __init__($$$) { $$$ } }'Length of output: 590
Script:
#!/bin/bash # Use ripgrep to search for the __init__ method of the YahooFinanceConnector class. rg "__init__" pandasai/connectors/yahoo_finance.pyLength of output: 115
Script:
#!/bin/bash # Use ripgrep to search for the __init__ method of the YahooFinanceConnector class with some lines of context. rg -C 3 "__init__" pandasai/connectors/yahoo_finance.pyLength of output: 471
docs/custom-head.md (1)
- 16-18: The update to instantiate
SmartDataframe
with theconfig
parameter as a named argument is correct and aligns with the PR objective to standardize the instantiation across documentation.docs/custom-instructions.md (1)
- 12-14: The change to the
SmartDataframe
instantiation correctly uses theconfig
parameter as a named argument, which aligns with the PR's objective to standardize instantiation patterns in the documentation.docs/custom-prompts.md (3)
34-37: The update to pass the
config
parameter as a named argument is correct and aligns with the PR's objective to standardize the instantiation ofSmartDataframe
.61-64: The change to pass the
config
parameter as a named argument in the instantiation ofSmartDataframe
usingMyCustomFileBasedPrompt
is also correct and consistent with the PR's objective.88-90: The instantiation of
SmartDataframe
without explicitly setting themy_custom_value
attribute in theconfig
parameter is consistent with the PR's objective to correct the documentation. However, it's important to ensure thatMyCustomPrompt
can handle cases wheremy_custom_value
is not provided.docs/custom-whitelisted-dependencies.md (1)
- 7-9: The updated code snippet correctly demonstrates how to instantiate
SmartDataframe
with theconfig
parameter, includingcustom_whitelisted_dependencies
. This is in line with the PR's objective to ensure that theconfig
parameter is passed as a named argument.docs/examples.md (14)
13-13: The import statement for
OpenAI
is correctly added according to the PR description and AI-generated summaries. This change is consistent across all examples.22-22: The instantiation of
OpenAI
with an API token is correct and follows the pattern described in the PR description. However, it's important to ensure thatYOUR_API_TOKEN
is a placeholder and that actual API tokens are not exposed in the documentation.25-25: The
SmartDataframe
instantiation now includes theconfig
parameter with thellm
key set to theOpenAI
instance, which aligns with the PR's objective to pass theconfig
parameter as a named argument.27-27: The
chat
method is used correctly to demonstrate the conversational capabilities of theSmartDataframe
. The output comment is informative and provides an example of the expected result.322-322: The
plot_salaries
function is correctly renamed and updated to accept a DataFrame parameter. The comment within the function provides a clear description of its purpose and usage.326-327: The plotting code within the
plot_salaries
function is correct, but it's important to ensure that the pathtemp_chart.png
is intended to be a temporary file or if it should be saved to a user-defined path as demonstrated in other examples.215-215: The instantiation of
SmartDataframe
with theconfig
parameter is repeated in multiple examples. While this repetition is necessary to show different use cases, it's important to ensure that the documentation clearly explains the purpose of theconfig
parameter to avoid confusion.216-216: The example demonstrates chaining commands using the
chat
method. It's important to verify that the output comment accurately reflects the capabilities of theSmartDataframe
and that the example is clear and understandable for users.256-258: The
Agent
class is instantiated with aconfig
parameter that includes thellm
key set to an instance ofOpenAI
, which is consistent with the changes made toSmartDataframe
andSmartDatalake
instantiations.160-165: The
SmartDataframe
instantiation includes multiple configuration options, demonstrating the flexibility of theconfig
parameter. It's important to ensure that thesave_charts_path
is explained clearly in the documentation and that the example uses a placeholder or a generic path that users can easily adapt.198-198: The instantiation of
SmartDatalake
with theconfig
parameter is consistent with the changes made toSmartDataframe
. This example helps to demonstrate the use of the library with multiple dataframes.299-299: The addition of custom functions to the
Agent
class is an advanced feature that should be explained clearly in the documentation. The example should demonstrate how users can define their own skills and add them to the agent.322-322: The
plot_salaries
skill function is correctly annotated with the@skill
decorator, indicating that it's a custom skill that can be added to theAgent
. The function's docstring provides a clear explanation of its purpose.326-327: The plotting code within the
plot_salaries
function usesmatplotlib
to generate a bar chart. It's important to ensure that the code follows best practices for plotting and that the saved chart is handled securely and appropriately.docs/getting-started.md (4)
47-47: The addition of the
OpenAI
import statement is consistent with the PR objectives to ensure proper instantiation and usage of theOpenAI
module in the examples.58-60: The instantiation of the
SmartDataframe
with theconfig
parameter as a named argument is a good practice and aligns with the PR objectives to correct parameter passing in the documentation.128-128: The import of the
OpenAI
module here is consistent with the PR objectives and ensures that theAgent
class is instantiated with the correct configuration.138-140: The instantiation of the
Agent
class with theconfig
parameter including anllm
key set to an instance ofOpenAI
is in line with the PR objectives and the AI-generated overview. This change ensures that theAgent
is configured correctly.docs/skills.md (1)
- 86-98: The parameter names in the
plot_salaries
function have been updated fromname
andsalary
tonames
andsalaries
. This change is consistent with the PR objectives and the AI-generated overview.
Most of the snippets were either outdated or didn't work at all
8ba331d
to
2e490e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 10
Configuration used: CodeRabbit UI
Files selected for processing (10)
- docs/LLMs/llms.md (2 hunks)
- docs/connectors.md (6 hunks)
- docs/custom-head.md (1 hunks)
- docs/custom-instructions.md (1 hunks)
- docs/custom-prompts.md (3 hunks)
- docs/custom-whitelisted-dependencies.md (1 hunks)
- docs/examples.md (14 hunks)
- docs/getting-started.md (5 hunks)
- docs/skills.md (3 hunks)
- examples/skills_example.py (1 hunks)
Files skipped from review due to trivial changes (1)
- docs/LLMs/llms.md
Files skipped from review as they are similar to previous changes (7)
- docs/connectors.md
- docs/custom-head.md
- docs/custom-instructions.md
- docs/custom-prompts.md
- docs/custom-whitelisted-dependencies.md
- docs/getting-started.md
- docs/skills.md
Additional comments: 5
docs/examples.md (3)
13-13: The addition of the
OpenAI
import from thepandasai.llm
package is consistent with the PR's objective to integrate theOpenAI
module in examples.22-25: The
SmartDataframe
instantiation now correctly includes theconfig
parameter as a named argument, aligning with the PR's objective to fix instantiation patterns.27-27: The
chat
method is correctly used with theSmartDataframe
object, demonstrating the interactive capabilities as intended in the PR.examples/skills_example.py (2)
24-30: The function signature and docstring for
plot_salaries
have been updated to use plural parameter names, which is consistent with the PR objective to correct parameter naming in the documentation.24-36: Ensure that the
plot_salaries
function is tested with the new parameter names to confirm that the agent's skill addition and subsequent chat interaction work as expected with the updated function signature.
Args: | ||
name (list[str]): Employee name | ||
salaries (list[int]): Salaries | ||
Displays the bar chart having name on x-axis and salaries on y-axis using streamlit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the docstring of the plot_salaries
function; "gpd" should be corrected to "gdp".
- Displays the bar chart having name on x-axis and salaries on y-axis using streamlit
+ Displays the bar chart having name on x-axis and salaries on y-axis using matplotlib
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
Displays the bar chart having name on x-axis and salaries on y-axis using streamlit | |
Displays the bar chart having name on x-axis and salaries on y-axis using matplotlib |
@@ -222,7 +253,7 @@ With the chat agent, you can engage in dynamic conversations where the agent ret | |||
|
|||
Feel free to initiate conversations, seek clarifications, and explore explanations to enhance your interactions with the chat agent! | |||
|
|||
``` | |||
```python | |||
import pandas as pd | |||
from pandasai import Agent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement for the Agent
class is missing, which is necessary for the code snippet to work correctly.
+ from pandasai import Agent
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from pandasai import Agent | |
from pandasai import Agent |
@@ -288,12 +319,9 @@ salaries_df = pd.DataFrame(salaries_data) | |||
|
|||
|
|||
@skill | |||
def plot_salaries(merged_df: pd.DataFrame) -> str: | |||
def plot_salaries(merged_df: pd.DataFrame): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plot_salaries
function is missing the merged_df
parameter in the agent.add_skills
method call. This will cause an error when the skill is invoked.
- agent.add_skills(plot_salaries)
+ agent.add_skills(plot_salaries(merged_df))
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def plot_salaries(merged_df: pd.DataFrame): | |
def plot_salaries(merged_df: pd.DataFrame): |
The plot_salaries
function does not return any value. If the function is intended to be used as a skill for the Agent
, it should return the path to the saved plot or the plot object itself.
+ return "temp_chart.png"
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def plot_salaries(merged_df: pd.DataFrame): | |
def plot_salaries(merged_df: pd.DataFrame): | |
return "temp_chart.png" |
@@ -222,7 +253,7 @@ With the chat agent, you can engage in dynamic conversations where the agent ret | |||
|
|||
Feel free to initiate conversations, seek clarifications, and explore explanations to enhance your interactions with the chat agent! | |||
|
|||
``` | |||
```python | |||
import pandas as pd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement for OpenAI
is duplicated in the "Working with Agent" section. It should be removed to avoid redundancy.
- from pandasai.llm.openai import OpenAI
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import pandas as pd | |
import pandas as pd |
@@ -265,7 +296,7 @@ print(response) | |||
|
|||
You can add customs functions for the agent to use, allowing the agent to expand its capabilities. These custom functions can be seamlessly integrated with the agent's skills, enabling a wide range of user-defined operations. | |||
|
|||
``` | |||
```python | |||
import pandas as pd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement for OpenAI
is duplicated in the "Add Skills to the Agent" section. It should be removed to avoid redundancy.
- from pandasai.llm.openai import OpenAI
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import pandas as pd | |
import pandas as pd |
import matplotlib.pyplot as plt | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plot_salaries
function uses a hardcoded filename for the saved plot. Consider using a dynamic filename or returning the plot object for better flexibility.
- plt.savefig("temp_chart.png")
+ plt.savefig("salaries_chart_{}.png".format(datetime.now().strftime("%Y%m%d%H%M%S")))
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
import matplotlib.pyplot as plt |
|
||
df = SmartDataframe("data/Loan payments data.csv") | ||
llm = OpenAI(api_token="YOUR_API_TOKEN") | ||
df = SmartDataframe("data/Loan payments data.csv", config={"llm": llm}) | ||
|
||
# We filter by males only | ||
from_males_df = df.chat("Filter the dataframe by women") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable from_males_df
is assigned the result of a chat command that filters by women, which is contradictory. The variable name should reflect the filter applied.
- from_males_df = df.chat("Filter the dataframe by women")
+ from_women_df = df.chat("Filter the dataframe by women")
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
from_males_df = df.chat("Filter the dataframe by women") | |
from_women_df = df.chat("Filter the dataframe by women") |
""" | ||
Displays the bar chart having name on x axis and salaries on y axis using streamlit | ||
Args: | ||
name (list[str]): Employee name | ||
names (list[str]): Employees' names | ||
salaries (list[int]): Salaries | ||
""" | ||
import matplotlib.pyplot as plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving the matplotlib.pyplot
import to the top of the module to avoid repeated imports if plot_salaries
is called multiple times, which can negatively impact performance.
salaries (list[int]): Salaries | ||
""" | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(name, salary) | ||
plt.bar(names, salaries) | ||
plt.xlabel("Employee Name") | ||
plt.ylabel("Salary") | ||
plt.title("Employee Salaries") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plt.xticks(rotation=45)
call appears to be outside the scope of the plot_salaries
function, which might be an error. If this line is intended to be part of the function, it should be indented accordingly.
Thanks a lot @mspronesti, super helpful! Documentation is becoming more and more a priority. Some many outdated parts! |
Hi @gventuri,
this PR fixes all the code snippets in the documentation. Most were either outdated or incorrect. Mostly:
config
needs to be passed as a named parameter (it's positionally not the second)docs/examples
were not properly instantiated and contained some typos.Summary by CodeRabbit
Documentation
DataBricksConnector
toDatabricksConnector
in import statements for clarity.name
andsalary
tonames
andsalaries
inplot_salaries
function for consistency.New Features
Refactor
config
parameter across various SmartDataframe instantiations for improved code maintainability.Style