Sinaptik-AI / pandas-ai

Chat with your database (SQL, CSV, pandas, polars, mongodb, noSQL, etc). PandasAI makes data analysis conversational using LLMs (GPT 3.5 / 4, Anthropic, VertexAI) and RAG.
https://pandas-ai.com
Other
11.7k stars 1.08k forks source link

ImportError: cannot import name 'Agent' from 'pandasai' #1250

Open NehaKoppikar opened 6 days ago

NehaKoppikar commented 6 days ago

System Info

OS Version: 14.4.1 Python Version: 3.9.7 PandasAI version: 0.2.2

🐛 Describe the bug

Unable to import Agent

Code used: import os import pandas as pd from pandasai import Agent

Sample DataFrame

sales_by_country = pd.DataFrame({ "country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"], "sales": [5000, 3200, 2900, 4100, 2300, 2100, 2500, 2600, 4500, 7000] })

By default, unless you choose a different LLM, it will use BambooLLM.

You can 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"] = ""

agent = Agent(sales_by_country) response = agent.chat('write insight about data') print(response)

dosubot[bot] commented 6 days ago

Hello @NehaKoppikar! I'm here to help you with any issues, questions, or contributions you have. Whether it's a bug or a query, feel free to ask me anything.

To resolve the ImportError when trying to import the Agent class from the pandasai library, ensure that you are importing it correctly from the pandasai.agent module. The correct import statement should be:

from pandasai.agent import Agent

This import statement should work as long as the pandasai library is properly installed and the pandasai/agent/agent.py file contains the Agent class definition. If you are still encountering issues, make sure that the pandasai library is installed in your environment. You can install it using pip if it is not already installed:

pip install pandasai

Additionally, you can refer to the unit tests provided in the tests/unit_tests/agent/test_agent.py file to ensure that your setup is correct. The tests include various scenarios for initializing and using the Agent class, which can help you verify that the class is being imported and used correctly in your environment [1][2][3].

To continue talking to Dosu, mention @dosu.