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.54k stars 1.21k forks source link

Pandas AI using Hugging Face models on local machine (PandasAIReader.__init__() got an unexpected keyword argument 'llm') #1318

Open Rumeysakeskin opened 1 month ago

Rumeysakeskin commented 1 month ago

System Info

llama-index 0.10.61
 llama-index-agent-openai 0.2.9 
llama-index-cli 0.1.13 
llama-index-core 0.10.61 
llama-index-embeddings-huggingface 0.2.2 
llama-index-indices-managed-llama-cloud 0.2.7
llama-index-legacy 0.9.48 
llama-index-llms-huggingface 0.2.5

🐛 Describe the bug

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, AwqConfig

model_id = "hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4"

llm = HuggingFaceLLM(
    context_window=8192, #4096
    max_new_tokens=512,
    generate_kwargs={"temperature": 0, "do_sample": False},
    system_prompt=system_prompt,
    query_wrapper_prompt=query_wrapper_prompt,
    tokenizer_name=model_id,
    model_name=model_id,
    device_map="auto",
    tokenizer_kwargs={"max_length": 8192} # 4096
)
from llama_index.readers.pandas_ai import PandasAIReader

loader = PandasAIReader(llm=llm)

I get below error:

----> 5 loader = PandasAIReader(llm=llm)

TypeError: PandasAIReader.init() got an unexpected keyword argument 'llm'

I noticed that PandasAIReader is generally used with OpenAI's LLM. Am I getting errors because I use it with HuggingFace? How can I resolve this issue?

dosubot[bot] commented 1 month ago

To resolve the TypeError: PandasAIReader.__init__() got an unexpected keyword argument 'llm' error, you need to ensure that you are using the correct class and its initialization parameters. The LangchainLLM class is likely the one you should be using for Hugging Face models.

Here is an example of how you might initialize and use the LangchainLLM class correctly:

from langchain_core.language_models import BaseLanguageModel
from pandasai.llm.langchain import LangchainLLM

# Initialize the BaseLanguageModel with the appropriate parameters
# Replace 'YourHuggingFaceModel' with the actual Hugging Face model you are using
huggingface_llm = BaseLanguageModel(model_name="YourHuggingFaceModel")

# Wrap the Hugging Face model with LangchainLLM
langchain_llm = LangchainLLM(langchain_llm=huggingface_llm)

# Use the initialized LLM with PandasAI
# Assuming you have a PandasAI instance and a DataFrame to work with
pandas_ai = PandasAI(llm=langchain_llm)
result = pandas_ai.run(your_dataframe, "your query")
print(result)

Make sure to replace "YourHuggingFaceModel", your_dataframe, and "your query" with the actual Hugging Face model name, your DataFrame, and your query respectively. This should resolve the TypeError by ensuring that the correct class and parameters are used [1][2][3].

To continue talking to Dosu, mention @dosu.