-
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
feat(skills): add skills to the pandas-ai library #653
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f890e67
feat(skills): add basic decorator for the skills
ArslanSaleem 2a3b526
Merge branch 'main' into feat/add_skills
ArslanSaleem fb4840f
feat(skills): add skills to dataframe and agent
ArslanSaleem c194483
feat(module): add func to module testing
ArslanSaleem 303884b
feat(skills): add skills execution code
ArslanSaleem 220a5ec
feat(skills): adding test cases for the code
ArslanSaleem af4ce21
feat(skills): add documentation
ArslanSaleem da513d0
feat(skills): remove whitelist lib extra
ArslanSaleem e5daabf
fix(skill): minor changes in the code and examples
ArslanSaleem d69ab37
chore(skills): use docstring for context
ArslanSaleem 413ba81
Merge branch 'release/v1.4' into feat/add_skills
ArslanSaleem 43d04dd
remove print statement
ArslanSaleem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Skills | ||
|
||
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. | ||
|
||
## Example Usage | ||
|
||
```python | ||
|
||
import pandas as pd | ||
from pandasai import Agent | ||
|
||
from pandasai.llm.openai import OpenAI | ||
from pandasai.skills import skill | ||
|
||
employees_data = { | ||
"EmployeeID": [1, 2, 3, 4, 5], | ||
"Name": ["John", "Emma", "Liam", "Olivia", "William"], | ||
"Department": ["HR", "Sales", "IT", "Marketing", "Finance"], | ||
} | ||
|
||
salaries_data = { | ||
"EmployeeID": [1, 2, 3, 4, 5], | ||
"Salary": [5000, 6000, 4500, 7000, 5500], | ||
} | ||
|
||
employees_df = pd.DataFrame(employees_data) | ||
salaries_df = pd.DataFrame(salaries_data) | ||
|
||
|
||
@skill( | ||
name="Display employee salary", | ||
description="Plots the employee salaries against names", | ||
usage="Displays the plot having name on x axis and salaries on y axis", | ||
) | ||
def plot_salaries(merged_df: pd.DataFrame) -> str: | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(merged_df["Name"], merged_df["Salary"]) | ||
plt.xlabel("Employee Name") | ||
plt.ylabel("Salary") | ||
plt.title("Employee Salaries") | ||
plt.xticks(rotation=45) | ||
plt.savefig("temp_chart.png") | ||
plt.close() | ||
gventuri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
llm = OpenAI("YOUR_API_KEY") | ||
agent = Agent([employees_df, salaries_df], config={"llm": llm}, memory_size=10) | ||
|
||
agent.add_skills(plot_salaries) | ||
|
||
# Chat with the agent | ||
response = agent.chat("Plot the employee salaries against names") | ||
|
||
|
||
``` | ||
|
||
## Add Streamlit Skill | ||
|
||
```python | ||
import pandas as pd | ||
from pandasai import Agent | ||
|
||
from pandasai.llm.openai import OpenAI | ||
from pandasai.skills import skill | ||
import streamlit as st | ||
|
||
employees_data = { | ||
"EmployeeID": [1, 2, 3, 4, 5], | ||
"Name": ["John", "Emma", "Liam", "Olivia", "William"], | ||
"Department": ["HR", "Sales", "IT", "Marketing", "Finance"], | ||
} | ||
|
||
salaries_data = { | ||
"EmployeeID": [1, 2, 3, 4, 5], | ||
"Salary": [5000, 6000, 4500, 7000, 5500], | ||
} | ||
|
||
employees_df = pd.DataFrame(employees_data) | ||
salaries_df = pd.DataFrame(salaries_data) | ||
|
||
|
||
@skill( | ||
name="Display employee salary", | ||
description="Plots the employee salaries against names", | ||
usage="Displays the plot having name on x axis and salaries on y axis", | ||
) | ||
def plot_salaries_using_streamlit(merged_df: pd.DataFrame) -> str: | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(merged_df["Name"], merged_df["Salary"]) | ||
plt.xlabel("Employee Name") | ||
plt.ylabel("Salary") | ||
plt.title("Employee Salaries") | ||
plt.xticks(rotation=45) | ||
plt.savefig("temp_chart.png") | ||
fig = plt.gcf() | ||
st.pyplot(fig) | ||
gventuri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
llm = OpenAI("YOUR_API_KEY") | ||
agent = Agent([employees_df, salaries_df], config={"llm": llm}, memory_size=10) | ||
|
||
agent.add_skills(plot_salaries_using_streamlit) | ||
|
||
# Chat with the agent | ||
response = agent.chat("Plot the employee salaries against names") | ||
print(response) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pandas as pd | ||
from pandasai import Agent | ||
|
||
from pandasai.llm.openai import OpenAI | ||
from pandasai.skills import skill | ||
|
||
employees_data = { | ||
"EmployeeID": [1, 2, 3, 4, 5], | ||
"Name": ["John", "Emma", "Liam", "Olivia", "William"], | ||
"Department": ["HR", "Sales", "IT", "Marketing", "Finance"], | ||
} | ||
|
||
salaries_data = { | ||
"EmployeeID": [1, 2, 3, 4, 5], | ||
"Salary": [5000, 6000, 4500, 7000, 5500], | ||
} | ||
|
||
employees_df = pd.DataFrame(employees_data) | ||
salaries_df = pd.DataFrame(salaries_data) | ||
|
||
|
||
@skill( | ||
name="Display employee salary", | ||
description="Plots the employee salaries against names", | ||
usage="Displays the plot having name on x axis and salaries on y axis", | ||
) | ||
def plot_salaries(merged_df: pd.DataFrame) -> str: | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(merged_df["Name"], merged_df["Salary"]) | ||
plt.xlabel("Employee Name") | ||
plt.ylabel("Salary") | ||
plt.title("Employee Salaries") | ||
plt.xticks(rotation=45) | ||
plt.savefig("temp_chart.png") | ||
plt.close() | ||
|
||
|
||
llm = OpenAI("YOUR_API_KEY") | ||
agent = Agent([employees_df, salaries_df], config={"llm": llm}, memory_size=10) | ||
|
||
agent.add_skills(plot_salaries) | ||
|
||
# Chat with the agent | ||
response = agent.chat("Plot the employee salaries against names") | ||
print(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,5 @@ | |
"base64", | ||
"scipy", | ||
"streamlit", | ||
"pandasai.skills", | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should probably show a less rigid implementation. What I have in mind is more something that lets the LLM orchestrate and pass the variable accordingly.
For example:
So that basically is the LLM that figures out which data to pass to the skill. The skill shouldn't be specific for one use case/df, but a more "generalist" function that can be used in many similar use cases, letting the LLM orchestrate and figuring out which one is the right one to use (if any).