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.67k stars 1.07k forks source link

There is a code error in the document #1211

Open tocer opened 2 weeks ago

tocer commented 2 weeks ago

System Info

pandasai==2.1 python==3.12

🐛 Describe the bug

https://docs.pandas-ai.com/llms#langchain-models

from pandasai import SmartDataframe
from langchain_openai import OpenAI

langchain_llm = OpenAI(openai_api_key="my-openai-api-key")
df = SmartDataframe("data.csv", config={"llm": langchain_llm})

OpenAI should be ChatOpenAI

dosubot[bot] commented 2 weeks ago

Hey there, @tocer! I'm here to help you with any bugs, questions, and contributions while waiting for a human maintainer. If you need assistance, feel free to ask!

The code snippet in the documentation should indeed use ChatOpenAI instead of OpenAI. Here is the corrected version:

from pandasai import SmartDataframe
from pandasai.llm import ChatOpenAI

llm = ChatOpenAI(api_token="my-openai-api-key")
df = SmartDataframe("data.csv", config={"llm": llm})

This change ensures that the correct class is used for initializing the OpenAI object with PandasAI [1][2].

To continue talking to Dosu, mention @dosu.