This module provides functionality for converting natural language queries into SQL queries.
To use this module, you need to have the following prerequisites:
- Python 3.x
- langchain library
You can install the langchain library using pip:
pip install langchainHere's an example of how to use the text2sql function provided by this module:
from .configimportLLM, PROMPTfromlangchainimportSQLDatabase, SQLDatabaseChainfromconverter.text2sqlimporttext2sql# Specify the database URLdb_url="your_database_url"# User input in natural languageuser_input="your_question"# Convert natural language to SQL queryresult=text2sql(db_url, user_input)
print("SQL Query:", result)Make sure to replace "your_database_url" with the actual URL of your database and "your_question" with the user's input.
The text2sql function takes a database URL and a user input string as parameters. It converts the natural language input into an SQL query using the langchain library and returns the resulting SQL query as a string.
Please note that you need to import the necessary modules and configure the OPENAI_KEY variable before using the text2sql function.