Open dustreturn opened 3 months ago
@dustreturn can you please confirm if you have used the right API key and passed it properly?
Because from the code you shared, it seems that you're not even making an llm call. One of the reasons for the same I think is that your LLM key is not passed / properly configured.
Hi, I noticed this bug, pre-defined functions is not been concat into generated code and lead to error.
You can call the following functions that have been pre-defined for you:
Update this initial code:
# TODO: import the required dependencies
import pandas as pd
# Write code here
# Declare result var:
type (possible values "string", "number", "dataframe", "plot"). Examples: { "type": "string", "value": f"The highest salary is {highest_salary}." } or { "type": "number", "value": 125 } or { "type": "dataframe", "value": pd.DataFrame({...}) } or { "type": "plot", "value": "temp_chart.png" }
有哪些一万亿以上市值的公司?
Variable dfs: list[pd.DataFrame]
is already declared.
At the end, declare "result" variable as a dictionary of type and value.
If you are asked to plot a chart, use "matplotlib" for charts, save as png.
Generate python code and return full updated code: 1456,0-1 59%
Generate python code and return full updated code:
2024-04-02 14:44:00 [INFO] Code generated:
# TODO: import the required dependencies
import pandas as pd
# Assuming dfs[0] is the DataFrame we are working with
df = dfs[0]
# Filter companies with market value over 1 trillion (一万亿)
# Note: The market value in the dataframe is assumed to be in 元, so 1万亿 = 1e12元
trillion_companies = df[df['市值'] > 1e12]
# Prepare the result
result = {
"type": "dataframe",
"value": trillion_companies[['股票代码', '公司名称', '市值']]
}
# Convert the market value to a more readable format using num_to_chinese_currency function
result['value']['市值'] = result['value']['市值'].apply(num_to_chinese_currency)
result
2024-04-02 14:44:00 [INFO] Executing Step 4: CachePopulation 2024-04-02 14:44:00 [INFO] Executing Step 5: CodeCleaning 2024-04-02 14:44:00 [INFO] Code running:
df = dfs[0]
trillion_companies = df[df['市值'] > 1000000000000.0]
result = {'type': 'dataframe', 'value': trillion_companies[['股票代码', '公司名称', '市值']]}
result['value']['市值'] = result['value']['市值'].apply(num_to_chinese_currency)
result
2024-04-02 14:44:00 [INFO] Executing Step 6: CodeExecution
2024-04-02 14:44:00 [ERROR] Failed with error: Traceback (most recent call last):
File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/pipelines/chat/code_execution.py", line 85, in execute
result = self.execute_code(input, code_context)
File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/pipelines/chat/code_execution.py", line 170, in execute_code
exec(code, environment)
File "
System Info
pandasai version: 2.0.23 platform: vscode
🐛 Describe the bug
import os import pandasai.pandas as pd from pandasai import Agent 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(names: list[str], salaries: list[int]): """ Displays the bar chart having name on x-axis and salaries on y-axis using streamlit Args: names (list[str]): Employees' names salaries (list[int]): Salaries """ import matplotlib.pyplot as plt
Get your FREE API key signing up at https://pandabi.ai.
You can also configure it in your .env file.
os.environ["PANDASAI_API_KEY"] = "YOUR_API_KEY"
agent = Agent([employees_df, salaries_df], memory_size=10) agent.add_skills(plot_salaries)
Chat with the agent
response = agent.chat("Plot the employee salaries against names") print(response)
response: Unfortunately, I was not able to get your answers, because of the following error:
'NoneType' object has no attribute 'type'