From be91d4a9011010deb5756ea7890e2abf462ecd7a Mon Sep 17 00:00:00 2001 From: gdcsinaptik Date: Fri, 13 Dec 2024 09:52:09 +0100 Subject: [PATCH 1/2] load and examples scripts --- new_examples/load_df.py | 11 ++++++ new_examples/quickstart.py | 24 +++++++++++++ new_examples/save_csv.py | 71 ++++++++++++++++++++++++++++++++++++++ new_examples/use_openai.py | 27 +++++++++++++++ pyproject.toml | 1 + 5 files changed, 134 insertions(+) create mode 100644 new_examples/load_df.py create mode 100644 new_examples/quickstart.py create mode 100644 new_examples/save_csv.py create mode 100644 new_examples/use_openai.py diff --git a/new_examples/load_df.py b/new_examples/load_df.py new file mode 100644 index 000000000..615a56440 --- /dev/null +++ b/new_examples/load_df.py @@ -0,0 +1,11 @@ +import os +import pandasai as pai + +os.environ["PANDASAI_API_URL"] = "http://localhost:8000/" +os.environ["PANDASAI_API_KEY"] = "PAI-test-key" + +# Load using organization/dataset format +#df = pai.load("/home/giuseppe/Projects/pandas-ai/datasets/testing/loans") +df = pai.load("/home/giuseppe/Projects/pandas-ai/datasets/testing/loans", virtualized=True) + +print(df.head()) \ No newline at end of file diff --git a/new_examples/quickstart.py b/new_examples/quickstart.py new file mode 100644 index 000000000..077c17101 --- /dev/null +++ b/new_examples/quickstart.py @@ -0,0 +1,24 @@ +import os +import pandasai as pai + +os.environ["PANDASAI_API_URL"] = "http://localhost:8000/" +os.environ["PANDASAI_API_KEY"] = "PAI-test-key" + +df = pai.read_csv("/home/giuseppe/Projects/pandas-ai/examples/data/Loan payments data.csv") + +# ask questions +# replace "Which are the top 5 countries by sales?" with your question +response =df.chat('How many loans are from men and have been paid off?') +print(response) + +img =df.chat('Plot the chart of loans paid off by men vs by women') +print(img) + +""" +#minimal save +df.save( + path="testing/loans", + name="loans", + description="Loans dataset" +) +""" \ No newline at end of file diff --git a/new_examples/save_csv.py b/new_examples/save_csv.py new file mode 100644 index 000000000..48ad6fe9a --- /dev/null +++ b/new_examples/save_csv.py @@ -0,0 +1,71 @@ +import os +import pandasai as pai + +os.environ["PANDASAI_API_URL"] = "http://localhost:8000/" +os.environ["PANDASAI_API_KEY"] = "PAI-test-key" + +df = pai.read_csv("/home/giuseppe/Projects/pandas-ai/examples/data/Loan payments data.csv") + +#save with fields descriptions +df.save( + path="testing/loans", + name="loans", + description="Loans dataset", + columns=[ + { + "name": "Loan_ID", + "type": "string", + "description": "Unique identifier for each loan" + }, + { + "name": "loan_status", + "type": "string", + "description": "Status of the loan (PAIDOFF, COLLECTION, COLLECTION_PAIDOFF)" + }, + { + "name": "Principal", + "type": "number", + "description": "The initial amount of the loan" + }, + { + "name": "terms", + "type": "number", + "description": "The duration of the loan in days" + }, + { + "name": "effective_date", + "type": "date", + "description": "The date when the loan became effective" + }, + { + "name": "due_date", + "type": "date", + "description": "The date when the loan payment is due" + }, + { + "name": "paid_off_time", + "type": "datetime", + "description": "The timestamp when the loan was paid off (if applicable)" + }, + { + "name": "past_due_days", + "type": "number", + "description": "Number of days the payment is past due (if applicable)" + }, + { + "name": "age", + "type": "number", + "description": "Age of the borrower" + }, + { + "name": "education", + "type": "string", + "description": "Education level of the borrower (High School or Below, Bechalor, college, Master or Above)" + }, + { + "name": "Gender", + "type": "string", + "description": "Gender of the borrower (male/female)" + } + ] +) \ No newline at end of file diff --git a/new_examples/use_openai.py b/new_examples/use_openai.py new file mode 100644 index 000000000..588d21e51 --- /dev/null +++ b/new_examples/use_openai.py @@ -0,0 +1,27 @@ +import os +import pandasai as pai +from pandasai_openai import OpenAI + +os.environ["PANDASAI_API_URL"] = "http://localhost:8000/" +os.environ["PANDASAI_API_KEY"] = "PAI-test-key" + +llm = OpenAI(api_token="your-key") +# Print LLM details +print("LLM Type:", type(llm).__name__) +print("LLM Instance:", llm) +print("LLM Model:", llm.model) + +pai.config.set({ + "llm": llm, +}) + +# Print current config to verify LLM setting +print("\nCurrent PandasAI Config:") +print("Active LLM:", pai.config._config.llm) + +df = pai.load("/home/giuseppe/Projects/pandas-ai/datasets/testing/loans") +print(df.head()) + +response = df.chat("What is the average age of the borrowers?") + +print(response) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index c16abe69b..88f2364fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ packages = [{include = "pandasai"}] python = ">=3.8,<3.9.7 || >3.9.7,<3.12" python-dotenv = "^1.0.0" pandas = "^2.0.3" +pyarrow = "^14.0.1" scipy = "1.10.1" astor = "^0.8.1" matplotlib = "^3.7.1" From e62bf33a8fb1defcf191426588eec33d6148b983 Mon Sep 17 00:00:00 2001 From: Gabriele Venturi Date: Fri, 13 Dec 2024 15:24:21 +0100 Subject: [PATCH 2/2] chore: fix typo Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- new_examples/save_csv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new_examples/save_csv.py b/new_examples/save_csv.py index 48ad6fe9a..09640060f 100644 --- a/new_examples/save_csv.py +++ b/new_examples/save_csv.py @@ -60,7 +60,7 @@ { "name": "education", "type": "string", - "description": "Education level of the borrower (High School or Below, Bechalor, college, Master or Above)" + "description": "Education level of the borrower (High School or Below, Bachelor, college, Master or Above)" }, { "name": "Gender",