forked from Sinaptik-AI/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* more robust print statement matching * preliminary cli tool * no token variation * takes in token as non required argument * add default value for token, specifiy dotenv path * multiple file format support, better error handling * fix: using click instead of argparse * chore: added click to list of dependencies * feat: add support for starcoder in the cli * fix: click as a dev dependency * feat: support all file types for pandas * fix: pylint issues * docs: add README instructions for pai * lint: fix lint --------- Co-authored-by: Gabriele Venturi <[email protected]>
- Loading branch information
1 parent
131f592
commit e0bcd23
Showing
8 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,7 @@ dist | |
pandasai.egg-info | ||
|
||
#venv | ||
/venv | ||
/venv | ||
|
||
# command line | ||
/pandasai_cli.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" Driver code for the CLI tool """ | ||
import os | ||
import click | ||
import pandas as pd | ||
from pandasai import PandasAI | ||
from pandasai.llm.openai import OpenAI | ||
from pandasai.llm.open_assistant import OpenAssistant | ||
from pandasai.llm.starcoder import Starcoder | ||
|
||
@click.command() | ||
@click.option('-d', '--dataset', type=str, required=True, help='The dataset to use.') | ||
@click.option('-t', '--token', type=str, required=False, default=None, help='The API token to use.') | ||
@click.option('-m', '--model', type=click.Choice(['openai', 'open-assistant', 'starcoder']), | ||
required=True, help='The type of model to use.') | ||
@click.option('-p', '--prompt', type=str, required=True, help='The prompt to use.') | ||
def main(dataset: str, token: str, model: str, prompt: str) -> None: | ||
"""Main logic for the command line interface tool.""" | ||
|
||
ext = os.path.splitext(dataset)[1] | ||
|
||
try: | ||
file_format = { | ||
".csv": pd.read_csv, | ||
".xls": pd.read_excel, | ||
".xlsx": pd.read_excel, | ||
".xlsm": pd.read_excel, | ||
".xlsb": pd.read_excel, | ||
".json": pd.read_json, | ||
".html": pd.read_html, | ||
".sql": pd.read_sql, | ||
".feather": pd.read_feather, | ||
".parquet": pd.read_parquet, | ||
".dta": pd.read_stata, | ||
".sas7bdat": pd.read_sas, | ||
".h5": pd.read_hdf, | ||
".hdf5": pd.read_hdf, | ||
".pkl": pd.read_pickle, | ||
".pickle": pd.read_pickle, | ||
".gbq": pd.read_gbq, | ||
".orc": pd.read_orc, | ||
".xpt": pd.read_sas, | ||
".sav": pd.read_spss, | ||
".gz": pd.read_csv, | ||
".zip": pd.read_csv, | ||
".bz2": pd.read_csv, | ||
".xz": pd.read_csv, | ||
".txt": pd.read_csv, | ||
".xml": pd.read_xml, | ||
} | ||
if ext in file_format: | ||
df = file_format[ext](dataset) # pylint: disable=C0103 | ||
else: | ||
print("Unsupported file format.") | ||
return | ||
|
||
except Exception as e: # pylint: disable=W0718 disable=C0103 | ||
print(e) | ||
return | ||
|
||
if model == "openai": | ||
llm = OpenAI(api_token = token) | ||
|
||
elif model == "open-assistant": | ||
llm = OpenAssistant(api_token = token) | ||
|
||
elif model == 'starcoder': | ||
llm = Starcoder(api_token = token) | ||
|
||
try: | ||
pandas_ai = PandasAI(llm, verbose=True) | ||
response = pandas_ai.run(df, prompt) | ||
print(response) | ||
|
||
except Exception as e: # pylint: disable=W0718 disable=C0103 | ||
print(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name = 'pandasai-cli', | ||
version = '0.1.2', | ||
packages = ['pai'], | ||
entry_points = { | ||
'console_scripts': [ | ||
'pai = pai.__main__:main' | ||
] | ||
} | ||
) |