-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from gventuri/release/v1.4
Release/v1.4
- Loading branch information
Showing
37 changed files
with
2,363 additions
and
102 deletions.
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
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,113 @@ | ||
# 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) | ||
|
||
# Function doc string to give more context to the model for use this skill | ||
@skill | ||
def plot_salaries(name: list[str], salaries: list[int]): | ||
""" | ||
Displays the bar chart having name on x axis and salaries on y axis | ||
Args: | ||
name (list[str]): Employee name | ||
salaries (list[int]): Salaries | ||
""" | ||
# plot bars | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(name, salaries) | ||
plt.xlabel("Employee Name") | ||
plt.ylabel("Salary") | ||
plt.title("Employee Salaries") | ||
plt.xticks(rotation=45) | ||
|
||
|
||
|
||
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) | ||
|
||
# Function doc string to give more context to the model for use this skill | ||
@skill | ||
def plot_salaries(name: list[str], salary: list[int]): | ||
""" | ||
Displays the bar chart having name on x axis and salaries on y axis using streamlit | ||
Args: | ||
name (list[str]): Employee name | ||
salaries (list[int]): Salaries | ||
""" | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(name, 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) | ||
|
||
|
||
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
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,47 @@ | ||
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) | ||
|
||
|
||
# Add function docstring to give more context to model | ||
@skill | ||
def plot_salaries(name: list[str], salary: list[int]) -> str: | ||
""" | ||
Displays the bar chart having name on x axis and salaries on y axis using streamlit | ||
Args: | ||
name (list[str]): Employee name | ||
salaries (list[int]): Salaries | ||
""" | ||
import matplotlib.pyplot as plt | ||
|
||
plt.bar(name, salary) | ||
plt.xlabel("Employee Name") | ||
plt.ylabel("Salary") | ||
plt.title("Employee Salaries") | ||
plt.xticks(rotation=45) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import pandas as pd | ||
from pandasai import Agent | ||
|
||
from pandasai.llm.openai import OpenAI | ||
|
||
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) | ||
|
||
# Example 1: Using Environment Variables | ||
os.environ["LOGGING_SERVER_URL"] = "SERVER_URL" | ||
os.environ["LOGGING_SERVER_API_KEY"] = "YOUR_API_KEY" | ||
|
||
|
||
llm = OpenAI("YOUR_API_KEY") | ||
agent = Agent( | ||
[employees_df, salaries_df], | ||
config={ | ||
"llm": llm, | ||
"enable_cache": True, | ||
}, | ||
memory_size=10, | ||
) | ||
|
||
# Chat with the agent | ||
response = agent.chat("Plot salary against department?") | ||
print(response) | ||
|
||
|
||
# Example 2: Using Config | ||
llm = OpenAI("YOUR_API_KEY") | ||
agent = Agent( | ||
[employees_df, salaries_df], | ||
config={ | ||
"llm": llm, | ||
"enable_cache": True, | ||
"log_server": { | ||
"server_url": "SERVER_URL", | ||
"api_key": "YOUR_API_KEY", | ||
}, | ||
}, | ||
memory_size=10, | ||
) | ||
|
||
# Chat with the agent | ||
response = agent.chat("Plot salary against department?") | ||
|
||
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
Oops, something went wrong.