From 3cdc6cb76f6aa79b52258a55b685d59ce4bf417e Mon Sep 17 00:00:00 2001 From: ArslanSaleem Date: Tue, 19 Sep 2023 16:17:02 +0500 Subject: [PATCH] fix: example of yahoo finance --- examples/from_snowflake.py | 16 +++++++++------- examples/from_yahoo_finance.py | 14 ++++++++++++++ pandasai/connectors/base.py | 1 - 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 examples/from_yahoo_finance.py diff --git a/examples/from_snowflake.py b/examples/from_snowflake.py index 4944f05fb..3df9968ef 100644 --- a/examples/from_snowflake.py +++ b/examples/from_snowflake.py @@ -1,28 +1,30 @@ """Example of using PandasAI with a Snowflake""" -from pandasai import SmartDatalake +from pandasai import SmartDataframe from pandasai.llm import OpenAI from pandasai.connectors import SnowFlakeConnector -snowflake_connector = SnowFlakeConnector(config={ - "account": "ehxzojy-ue47135", +snowflake_connector = SnowFlakeConnector( + config={ + "account": "ehxzojy-ue47135", "database": "SNOWFLAKE_SAMPLE_DATA", "username": "test", "password": "*****", "table": "lineitem", - "warehouse" : "COMPUTE_WH", + "warehouse": "COMPUTE_WH", "dbSchema": "tpch_sf1", "where": [ # this is optional and filters the data to # reduce the size of the dataframe - ["l_quantity", ">","49"] + ["l_quantity", ">", "49"] ], - }) + } +) OPEN_AI_API = "Your-API-Key" llm = OpenAI(api_token=OPEN_AI_API) -df = SmartDatalake([snowflake_connector], config={"llm": llm}) +df = SmartDataframe(snowflake_connector, config={"llm": llm}) response = df.chat("Count line status is F") print(response) diff --git a/examples/from_yahoo_finance.py b/examples/from_yahoo_finance.py new file mode 100644 index 000000000..78b07495e --- /dev/null +++ b/examples/from_yahoo_finance.py @@ -0,0 +1,14 @@ +from pandasai.connectors.yahoo_finance import YahooFinanceConnector +from pandasai import SmartDataframe +from pandasai.llm import OpenAI + + +yahoo_connector = YahooFinanceConnector("MSFT") + + +OPEN_AI_API = "OPEN_API_KEY" +llm = OpenAI(api_token=OPEN_AI_API) +df = SmartDataframe(yahoo_connector, config={"llm": llm}) + +response = df.chat("closing price yesterday") +print(response) diff --git a/pandasai/connectors/base.py b/pandasai/connectors/base.py index 6e0fed803..0fd429baf 100644 --- a/pandasai/connectors/base.py +++ b/pandasai/connectors/base.py @@ -83,7 +83,6 @@ def _load_connector_config(self, config: Union[BaseConnectorConfig, dict]): """ pass - @abstractmethod def _init_connection(self, config: BaseConnectorConfig): """ make connection to database