Package: pipableai
PipableAI 🚀AboutPipableAI is a Python package that simplifies the process of querying a database. It provides a high-level interface for connecting to a remote database server, generating and executing natural language-based data search queries mapped to database queries using a language model.Current FeaturesNatural Language Queries: Express database queries in plain English.PostgreSQL Integration: Seamlessly connects to PostgreSQL databases.Language Model Mapping: Translates natural language queries into SQL queries.Structured Results: Returns query results in a structured format for easy processing.InstallationTo install PipableAI, you can usepip3, Python's package manager. Open your terminal or command prompt and run the following command:pip3installpipableaiNote:PipableAI requires Python 3.7 or higher.If you prefer to install PipableAI from source, you can clone the GitHub repository and install it usingsetup.py. Navigate to the project directory and run:python3setup.pyinstallThis will install PipableAI locally on your system.UsagePipableAI simplifies the process of connecting to a remote db servers, generating SQL queries using a language model, and executing them. This section provides a step-by-step guide on how to use PipableAI effectively in your Python projects.Import Pipable:To start using PipableAI, import the necessary classes:frompipableaiimportPipablefrompipableai.llm_client.pipllmimportPipLlmApiClientfrompipableai.core.postgresql_connectorimportPostgresConfig,PostgresConnectorInitialize Pipable:Create an instance of Pipable by providing the required database configuration and LLM API base URL:# Define PostgreSQL configurationpostgres_config=PostgresConfig(host="your_postgres_host",port=5432,# Replace with your port numberdatabase="your_database_name",user="your_username",password="your_password",)# Initialize the database connector and LLM API clientdatabase_connector=PostgresConnector(postgres_config)llm_api_client=PipLlmApiClient(api_base_url="https://your-pipllm-api-url.com")# Create a Pipable instancepipable_instance=Pipable(database_connector=database_connector,llm_api_client=llm_api_client)Generate and Execute Queries:Generate SQL queries using the language model and execute them on the database.
For Better Performance one can pass the tables names which shold be used in the queryWhentable_namesis None or not passed in:question="List all employees."# Generate the querytry:result_df=pipable_instance.ask(question)print("Query Result:")print(result_df)exceptExceptionase:print(f"Error:{e}")# Generate and execute the querytry:result_df=pipable_instance.ask_and_execute(question)print("Query Result:")print(result_df)exceptExceptionase:print(f"Error:{e}")Whentable_namesis populated with correct table names:table_names=["table1","table2","table3"]question="List all employees."# Generate and execute the querytry:result_df=pipable_instance.ask_and_execute(question,table_names)print("Query Result:")print(result_df)exceptExceptionase:print(f"Error:{e}")table_names=["table1","table2","table3"]question="List all employees."# Generate the querytry:result_query=pipable_instance.ask(question,table_names)print("Query Result:")print(result_query)exceptExceptionase:print(f"Error:{e}")Whentable_namesis an empty list:table_names=[]question="List all employees."# Generate and execute the querytry:result_df=pipable_instance.ask_and_execute(question,table_names)print("Query Result:")print(result_df)exceptExceptionase:print(f"Error:{e}")Handle exceptions appropriately to ensure graceful error handling in your application.Disconnect from the Database:Close the connection to the PostgreSQL server after executing the queries:pipable_instance.disconnect()ordatabase_connector.disconnect()Ensure that you disconnect from the database to release resources when the queries are completed.Additional Information:Check the interfaces:DatabaseConnectorInterfaceandLlmApiClientInterfacefor more details on the methods and functionalities provided by Pipable.ExampleFor a complete example, refer to theexample/directory in this repository.DocumentationFor detailed usage instructions and examples, please refer to theofficial documentation.ContributingWe welcome contributions from the community! To contribute to Pipable, follow these steps:Fork the repositoryCreate a new branch:git checkout -b feature-nameMake changes and commit:git commit -m 'Description of changes'Push to the branch:git push origin feature-nameSubmit a pull requestPlease read ourContribution Guidelinesfor more details.LicenseThis project is licensed under the Apache 2.0 - see theLICENSEfile for details.