This repository hosts a proof of concept for integrating OpenAI's ChatGPT with an Azure SQL Database to facilitate answering questions using data within the database. The integration aims to provide a seamless natural language querying interface.
Demo.mp4
As part of our commitment to security best practices, the server credentials and API key used during the development of this POC have been permanently deleted and are no longer available. You should create your SQL Database and have your own Open AI api key.
The process flow of the integration is detailed in the workflow diagram included in the repository. Each step in the workflow is implemented as a function in src/gpt_db_assistant.py
, with comments in the code that correspond to the description in the workflow boxes.
- User makes a question (Actor): The interaction begins with the user's natural language question.
- GPT receives the question: ChatGPT processes the question and gathers necessary information from the database tables.
- GPT returns a query: ChatGPT formulates a SQL query to retrieve the answer from the database.
- The query is executed: The SQL query is run against the Azure SQL Database.
- Query Execution Feedback Loop:
- If the query is successful, the result is submitted back to GPT to check if it answers the user's question.
- If the query fails, ChatGPT attempts to generate a new query. This error handling loop continues for a maximum of three attempts before concluding to restart the process.
- Answering the User's Question:
- If the query result is satisfactory, ChatGPT returns the final answer to the user.
- If after three attempts the result is still not satisfactory, the process concludes and a restart is suggested.
notebooks
: Contains Jupyter notebooks for exploratory purposes and initial testing.src
: Includes the main Python code.
- Set up an Azure SQL Database with the necessary data.
- Obtain an API key from OpenAI for accessing ChatGPT.
- Clone this repository to your local machine.
- Update the
src/config.ini
file - Install the dependencies listed in
requirements.txt
. - streamlit run src/main.py