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
12.92k stars 1.25k forks source link

LLMNotFoundError in v2.0 #972

Closed Rainismer closed 7 months ago

Rainismer commented 7 months ago

System Info

from pandasai import SmartDataframe from langchain_openai import AzureChatOpenAI import pandas as pd

llm = AzureChatOpenAI( openai_api_key=config.azure_openai_api_key, openai_api_version=config.azure_openai_api_version, azure_endpoint=config.azure_openai_endpoint, azure_deployment=config.model_name ) 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] }) df = SmartDataframe(sales_by_country, config={"llm": llm}) response = df.chat('Which are the top 5 countries by sales?') print(response)

🐛 Describe the bug

Traceback (most recent call last): File "D:\Projects\dataCopilot-web\333.py", line 163, in df = SmartDataframe(sales_by_country, config={"llm": llm}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pandasai\smart_dataframe__init.py", line 64, in init self._agent = Agent([df], config=config) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pandasai\agent\base.py", line 74, in init config = self.get_config(config) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pandasai\agent\base.py", line 147, in get_config config = Config(**config) ^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pydantic\v1\main.py", line 339, in init values, fields_set, validation_error = validate_model(pydantic_self.class__, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pydantic\v1\main.py", line 1074, in validatemodel v, errors = field.validate(value, values, loc=field.alias, cls=cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pydantic\v1\fields.py", line 895, in validate v, errors = self._apply_validators(v, values, loc, cls, self.post_validators) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pydantic\v1\fields.py", line 1154, in _apply_validators v = validator(cls, v, values, self, self.model_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pydantic\v1\class_validators.py", line 304, in return lambda cls, v, values, field, config: validator(cls, v) ^^^^^^^^^^^^^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pandasai\schemas\df_config.py", line 41, in validate_llm raise LLMNotFoundError("LLM is required") pandasai.exceptions.LLMNotFoundError: LLM is required

gventuri commented 7 months ago

Hi @vaguely_happy check out this video: https://app.gemoo.com/video/video-details/comment/621622223857717248?codeId=MlQ5yGpLeN59r

Basically, what you need to do is generating a API key from https://pandabi.ai/ and pass it, then you should be allowed to use the train method 🙂 Here's an example: import os

from pandasai import Agent

Set your PandasAI API key (you can generate one signing up at https://pandabi.ai)

os.environ["PANDASAI_API_KEY"] = "YOUR_PANDASAI_API_KEY"

agent = Agent("examples/data/Loan payments data.csv")

Example #1: train the model with docs

agent.train(docs="Only return loans information about the past 10 years")

response = agent.chat("How many loans were paid off?") print(response)

You can also see the updated docs: https://docs.pandas-ai.com/en/latest/train/#train-with-your-own-settings

Hrishikesh-Dutta0078 commented 7 months ago

@gventuri Does it support Azure OpenAI llm yet? Its working on OpenAI apitoken but not on AzureOpenAI