Open Pranathipatelhe opened 9 months ago
+1 on the issue. Facing the same.
Hello @alessioricco , @alessiodashydash , @kairavdashydash , @muhammad-abdullah-dashy-dash ,
I believe this issue is occurring as the code is using openai.ChatCompletion
method, but this is no longer supported in openai>=1.0.0
.
I think this can be fixed by replacing openai.ChatCompletion
with the client.chat.completions.create
method. My idea is to create an attribute in the PandasLLM class to hold the openai client and then, use this client to make calls to the chat.completions.create
in prompt
method. I have tested it on my machine and it works.
I am happy to submit a PR if you are fine with the proposed fix or if you have other fixes, happy to discuss.
+1 same here.
@deathsaber if you think you can fix the issue, I'd say submit the PR and let's see if @alessioricco @alessiodashydash can approve and merge.
@elgaeloHub - Well, I tried pushing a fix but my push got rejected.
git -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/fix/issue-7:fix/issue-7 --set-upstream
remote: Permission to DashyDashOrg/pandas-llm.git denied to deathsaber.
fatal: unable to access 'https://github.com/DashyDashOrg/pandas-llm.git/': The requested URL returned error: 403
I'm guessing the authors of the repo plan to archive it due to the RCE mentioned in issue 5.
If your use-case is running natural language queries on structured data, I'd advice you check out this library. It's working great for me.
If you still wanna use pandas-llm
, then the changes you need are given below -
openai==1.30.1
in requirements.txt and install it.__init__
method of the PandasLLM class - self.openai_client = openai.OpenAI(api_key=self.llm_api_key)
prompt
method of the PandasLLM class inside the try-except
block to response = self.openai_client.chat.completions.create( model=self.model, temperature=self.temperature, messages=messages )
and you should be good to go.Hi All, I left the company, and I'm not maintaining the project. The issue is due to the old openai lib version, as @deathsaber pointed out. If you want to continue using the library, I'm happy to help you and continue to support it. the new forked repo is here: https://github.com/alessioricco/pandas-llm
@Pranathipatelhe I receive a "Please Retry later" error if I don't have the OPEN_AI_KEY set just write a .env file, add your valid OPENAI_API_KEY And you will have the result.
@deathsaber, the problem is not the version of the open library because, in the requirements.txt, the correct library is defined as the old one. I will change it so we can support the new classes. I also fixed the Sandbox issue, but as I said in the previous message, I can't support this project here, so I forked to my repo. If you are still interested, please move there.
Code: import os import pandas as pd from pandas_llm import PandasLLM
Data
Please note that these names, ages, and donations are randomly generated
and do not correspond to real individuals or their donations.
data = [('John Doe', 25, 50), ('Jane Smith', 38, 70), ('Alex Johnson', 45, 80), ('Jessica Brown', 60, 40), ('Michael Davis', 22, 90), ('Emily Wilson', 30, 60), ('Daniel Taylor', 35, 75), ('Sophia Moore', 40, 85), ('David Thomas', 50, 65), ('Olivia Jackson', 29, 55)] df = pd.DataFrame(data, columns=['name', 'age', 'donation'])
conv_df = PandasLLM(data=df, llm_api_key =API_KEY) result = conv_df.prompt("What is the average donation of people older than 40 who donated more than $50?") code = conv_df.code_block
print(f"Executing the following expression of type {type(result)}:\n{code}\n\nResult is:\n {result}\n")
Executing the following expression of type <class 'numpy.float64'>:
result = df.loc[(df['age'] > 40) & (df['donation'] > 50), 'donation'].mean()
Result is:
72.5
Error: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access conv_df = PandasLLM(data=df, llm_api_key =API_KEY) Executing the following expression of type <class 'str'>:
Result is: Please try later
Even though I am trying with same code which is given in the pandas-llm documentation, I always encounter with 'Please try later' response. @alessioricco @alessiodashydash @kairavdashydash @muhammad-abdullah-dashy-dash