We are going to build a Slack bot in Python. The bot will access OpenAI’s GPT-3 model and a sqlite database. Of course, you can replace sqlite with any other database. The AI model will produce standard SQL. It should work fine with every SQL database and query engine.
A Langchain Agent allows GPT-3 to perform operations in the “outside world.” With those agents, we can retrieve data from the Internet, run code generated by GPT-3, or access a database. The GPT-3 will determine on its own what actions it needs to take and in what order. Every action’s output will be automatically returned to the model by the langchain library.
When the agent implementation uses the GPT-3 model, the model can determine what information it needs to answer the question and which of the available actions provides the required data. It also knows how to use the action correctly (GPT-3 automatically generates those SQL queries), understands the answer, and paraphrases it to answer the original question.
My database contains the Titanic Dataset split into three tables. A “tickets” table includes the ticket id, class, fare, cabin number, and port of embarkation. Every row is linked to a passenger by the passenger’s id. The third table contains the passengers’ data: name, sex, age, number of siblings, spouses, parents, and children aboard the Titanic. I have the “survivors” table with only two columns: the passenger’s id and a boolean to indicate whether a person survived.