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.71k stars 1.09k forks source link

Unfortunately, I was not able to get your answers, because of the following error:\n\n'NoneType' object has no attribute 'type'\n #1054

Closed nothk closed 3 months ago

nothk commented 3 months ago

System Info

windows 10, python 3.9.5

🐛 Describe the bug

I run this default code, but get error "Unfortunately, I was not able to get your answers, because of the following error:\n\n'NoneType' object has no attribute 'type'\n"

I did something wrong? what should I do?

thanks

import os
import pandas as pd
from pandasai import SmartDataframe

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]
})

# I get my API key from https://www.pandabi.ai/admin/api-keys, it's free? this API can provide LLM function?
# I replaced YOUR_API_KEY by API_key from https://www.pandabi.ai/admin/api-keys
os.environ["PANDASAI_API_KEY"] = "YOUR_API_KEY"

agent = SmartDataframe(sales_by_country)
agent.chat('Which are the top 5 countries by sales?')
ysh-core42 commented 3 months ago

same problem here, on Mac, python 3.9

YarShev commented 3 months ago

Hi @nothk and @ysh-core42, could you tell us what version of pandas-ai you are experiencing the issue with?

nothk commented 3 months ago

Hi @nothk and @ysh-core42, could you tell us what version of pandas-ai you are experiencing the issue with?

pandasai.version 2.0.21

thekakodkar commented 3 months ago

Same error on Windows 11 Enterprise , python 3.10.11 ; panadasai 2.0.3

YarShev commented 3 months ago

The issue doesn't seem to be related to the upgrading pandas version. @gventuri, any insight on this?

Jonatasmz commented 3 months ago

same error on Latest version of Ubuntu, Python 3.9.16, panadasai 2.0.21

YarShev commented 3 months ago

I see the same error with pandasai==2.0.16 if I install pandasai with pip. However, if I work with main branch and install dependencies with poetry the code example passes. It is really confusing. @gventuri, might it be a case that PyPI package is missing some necessary files?

thekakodkar commented 3 months ago

I tried to update the extra dependencies using pip install pandasai[streamlit] after which the error I get now is " 'NoneType' object has no attribute 'call'

YarShev commented 3 months ago

I looked into the code and found the place where the error is raised, the line is. https://github.com/Sinaptik-AI/pandas-ai/blob/5d4753a2b46d968559ec1132af2f5f511bea45e7/pandasai/agent/base.py#L254

PyPI pandasai package is missing pandasai.json file, where the config is loaded from. Since there is no this file, self.context.config.llm is None and thus when accesing self.context.config.llm.type the error is raised.

'NoneType' object has no attribute 'type'

I am not sure if the file is not present intentionally so letting @gventuri shed light on this.

YarShev commented 3 months ago

Just as a workaround you could place pandasai.json file in the root directory of the installed pandasai package.

thekakodkar commented 3 months ago

I tried adding the json file, upgraded the pandasai; still gives me "ValueError: Invalid input data. We cannot convert it to a dataframe."

YarShev commented 3 months ago

Indeed, this workaround doesn't seem to be working. I got AttributeError: module 'pandasai.llm' has no attribute 'BambooLLM'. Let's wait for a response from a maintainer.

sanjivjha commented 3 months ago

I am also getting the same error, installed latest pandasai

qcxia20 commented 3 months ago

Just as a workaround you could place pandasai.json file in the root directory of the installed pandasai package.

This is right. Just want to supplement that the root directory is by default current directory. https://github.com/Sinaptik-AI/pandas-ai/blob/5d4753a2b46d968559ec1132af2f5f511bea45e7/pandasai/helpers/path.py#L11-L25 So you may need to set the environment variable PANDASAI_WORKSPACE and ensure that path has pandasai.json.

rafabelokurows commented 3 months ago

I had the same issue, but creating a environment variable named PANDASAI_WORKSPACE and pointing to a directory where pandasai.json was made it work for me :) Thanks @YarShev and @qcxia20

Valdegg commented 3 months ago

Adding the env file and the json made pandasai work for some cases, but I still get absurd errors, such as:

Unfortunately, I was not able to answer your question, because of the following error:

'type'

Executing "sdf.last_code_generated" works though... So it's some bug in the chat pipeline?

gventuri commented 3 months ago

Try to upgrade to 2.0.22, should be fixed now! Closing :)

thekakodkar commented 3 months ago

Not sure if its related but after I upgrade the pandasai to 2.0.23, I get the below error

Request failed: HTTPSConnectionPool(host='api.domer.ai', port=443): Max retries exceeded with url: /api/training-data/qa/relevant-qa?query=%23%23%23+QUERY%0A+How+many+loans+are+from+men+and+have+been+paid+off%3F&count=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)')))

Riofd commented 3 months ago

Try to upgrade to 2.0.22, should be fixed now! Closing :)

Sorry to disturb you again. I still have the same error in 2.0.24. I want to know how to solve this now.

PedroGarcia0202 commented 3 months ago

Today i receive this error in pandasia 2.0.25. Some new solution ?

jaiminee commented 3 months ago

2.0.22

Hi, I upgraded to this version but getting this error ( running code in Amazon Sagemaker Jupyterlab)

  1. Do I need API key to add in my code?
  2. Tried LLamCPP with llama-2-7b, still not working.
Screenshot 2024-03-27 at 12 30 33 PM Screenshot 2024-03-27 at 12 29 13 PM
Riofd commented 3 months ago

Try to upgrade to 2.0.22, should be fixed now! Closing :)

Sorry to disturb you again. I still have the same error in 2.0.24. I want to know how to solve this now.

When I use the openai model, it works well. So I suppose the reason is my pandasai-api account has no billing or access.

ArslanSaleem commented 3 months ago

Hi @nothk,

I encountered this issue in Jupyter Notebooks. Strangely, llm was None, although it wasn't the case when running from a .py file.

This PR should fix the issue https://github.com/Sinaptik-AI/pandas-ai/pull/1070

flashtheman commented 3 months ago

I confirm that the bug still persists. The error only occurs when using agent.chat.

ArslanSaleem commented 3 months ago

@flashtheman,

How did you verify that? Did you check out my branch or did you find it through pip? Please note that the fix PR has not been released yet.

flashtheman commented 3 months ago

@flashtheman,

How did you verify that? Did you check out my branch or did you find it through pip? Please note that the fix PR has not been released yet.

Sorry, I was referring to the current version!