Chat with Your SQL Data Using ChatGPT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] mg can you debug this SQL query that I developed there's a error message here but I cannot resolve it did you develop all these SQL codes yeah that was a pain man that's too many SQL queries with all these mess I cannot help you so what can I do now instead of developing all these Circle queries you can have a conversation with your data I mean you can chat with your tabular data as you have conversation with me right now talking with my tabular data he is hallucinating again I worry about him no no cut we're gonna record this part again listen when you say I'm worried about him you have to show it in your facial expression and in your vocal tone as well right so let's record this part again I can't because I don't really care about you not even I'm not sure which one of us really exists in real world [Music] thank you okay now if you want to check how you can talk or have conversation with your tabular data using chat gbt this is the right video for you and let's go hello everyone this is mg welcome to another video well we previously recorded two videos about how you can use chat GPC and open your capabilities to be able to have conversation with your data or chat with your data while talking about data we mainly focus on on a structured data means Text data sets or PDF files or even some images that you have some documents embedded within the images so we were able to develop a web application that we could chat and ask any question that we have from our text or PDF files so on and so forth now in this video as you ask we're gonna check how we can do the same thing I mean having conversation with your data but this time tabular data let's say you have large amount of data set embedded in a SQL database and instead of you developing SQL queries you want to get the same outcome but without developing SQL queries let's say you want to ask describe table X for me within that SQL database that I have so the outcome going to be there immediately like a conversational manner of course using chat GPT on packing and open AI capabilities so if you want to check it out how you can replace your SQL queries with a conversational based request to start chatting with your tabular data using chatgpt then let's check it out before we start make sure you subscribe and hit the Bell icon so you will get notified for the next video thank you all right so now what we're gonna do in this video I'm going to actually chat and I can have conversation but this time with my tabular data well here is a very quick simple UI I'm not developing any web app stuff just wanted to show you the flow of how I can ask any question from my table the tabular data which is here a sqlite and the result's got to be back in a conversational format without me developing and asking here any SQL based query first of all before I start asking any questions about my data and before I go through the codes and see all the stuff on the backhand side let's see what is my data well here I have developed this sample and the GitHub repository of all the codes I'm going to execute here I created repo and in my GitHub and I will add the link of my repo that I have all these codes that are going to show in this tutorial in that GitHub so you can check that out but I have developed this code and made some changes changes based on Lang an example and their report so I'm going to talk about what is line trainer stuff but let's talk about what is the data well the data that I have is actually a sqlite database again I use from that sample and in this SQL light database first you can see there is a code in the repository there's a DOT SQL code in the repository that will create this sqlite for me so if in order to you run this manually and create all this table of stuff to create this database as an example for this demo this script is doing this for you so if I open up dot SQL code that I have if you check out again the repo of mine that I will add the link in video description there is a file called Chinook sqlite.sql and here's here's the data so it is creating some table again uh simulated data about some artist with the artist ID and the album that they have sang their songs the title of the album uh some information about customers that they purchased those the customer first name last name some more information about let's say for example the length of the track or song the genre the invoice of that purchase for a specific let's say song or invoice line media type for example playlist playlist track table so you can see I'm creating multiple tables here and if you want to check what is the value inside these tables that we are creating well this sample code is then inserting the values to each table for example there we are appear we are inserting value inside artists table and the values are artist ID and the name and you can see these are fake names of course if I scroll all the way down you can see all these SQL code is inserting values for the tables we have specified on the top okay so now I have already created a sqlite database on my machine using the SQL code and I'm going to show you how but now my database base is there and I'm going to use open AI to start query ask questions like a chat from this data and database okay again here's a very simple UI nothing fancy just to show you the flow of how it's going to work for example the first question that I want to ask is I know that there is a table called playlist track for those songs and I want to know some information about what columns I have what is this schema stuff but there is a SQL query for that but I don't want to write down a SQL query so I want to talk in a natural conversational manner right so I would say describe their playlist track table okay nothing fancy I click on chat and I'm expecting the results gonna be back again I'm going to show you the back end how it is retrieving back to info but there you go it is telling me your table within that database has two columns playlist ID and track ID and is related to the playlist and track tables so it's telling me what is the key stuff and even it retrieving back as an example of some three rows of that table as an example with their values let's try another information for example let's ask something that needs some calculation like merging joining tables uh do averages stuff whatever let's say I want to at least the total cells per country also which country 's customer spent the most right so it needs some calculation and stuff not just the select query all right let's click on chat let me grab some coffee until it's gonna retrieve back the results there you go the customer from USA spent the most with the total this is truly amazing I'm not typing any SQL code here I'm asking like how I talk as a human and the results is packed fully not through a code something like a human readable output so you can certainly when you run this demo in the GitHub repo of mine that I'm going to add to the video description write down any questions that you want that I was playing around asking different questions last night it is really impressive although it is based on Lang chain and Lang chain mentioned in the documentation it is evolving so you might not be able to ask very complex question that runs over a complex query but as soon that's a great tool and capable of doing so many casual scenarios so there is a code in the repo that I'm gonna add in the video uh description called UI dot pi that is actually generating this very simple UI and if you run this you need to just replace the Azure open AI sorry open AI key value I'm not using Azure open AI here so you can just grab your opening a key from opening a website you need to add your payment information there and you will grab a key put that key in the uipi.com ui.pi code and just run it it will open up this UI free and you can start asking questions but in order to show you how this sort of magical output is getting generated and how you're dealing with open Ai and Lang chain let's go to the notebook that I Pi Y and B this is also available in the repo that doesn't generate UI but you will see that you can ask these questions in the notebook and the results gonna be back with chain of thoughts okay let me minimize this there you go that's the notebook again available inside the repo and what I'm gonna do first again you need to create that database or sqlite using that dot SQL notebook that is available in the report right so first you need to give it a name again this is coming from what launching also used in the example it can be any database that can be yours then you need to start putting some values inside that database how again using this dot SQL code that is coming in with the repo and then after executing that this is gonna create that database with the values that is generated inside this notebook and that's it right now if you want to test if you can if your database is there created and you can work with it start creating some queries here for example I asked select everything from that table and show me just the first 10. and that's it it retrieved the result back so that means my database is created and it has values it was just a test let's go now what I'm going to do I want to ask questions about this database without creating these type of SQL queries so let's say I want to do the same thing but here I want to ask questions like a human natural language okay so let's do this first of course you need to have your open AI key again go to open your website put your payment information there grab the key and paste it here I I remove mine this is credential and then you need to also make sure Lang chain is installed so I have added the instruction of how you need to install the environment ready before you run this demo in my repo you will read that there but just simply do pip install chain and then also pip install open AI make sure these two are installed and then you can import this stuff from link chain so what is line chain well Langston team said that we have now great large language models or llm models that they can generate code generate text in order to make your life easier when you want to create application using these large language models Lang chain is started to create some rap wrapped functionalities over these launch language models one of these sort of Rapid solution over large language models is creating a SQL agent that can talk with your SQL database through large language models here openingi so this is sort of the magic secret here chat GPT an open API openai models are just language models that they can generate text that means I cannot use chat GPT to run a SQL query I cannot use chat GTP as a server for my database so that means this is just a model that can generate text and generate code so instead of me expecting chat gbt to do math calculation or SQL code execution which is not possible it's not like an engine like a server of a database what you can do chat GPT or open your models can instead generate SQL codes and then you run the SQL codes over your own server to have the results back so that means when I ask for example question list the total sales per country it is going to ask chargpt they are generate a SQL code that does this for me and bring that SQL code back over a server that I have this database and run that SQL query and get the results of the SQL query back to me in a language or conversational format so this is the trick but you can see this back and forth has been done through a wrapped Solution by launching so this is the contribution of Langston I'm not going to customize and develop this it's already there I just need to connect to my database and then start asking connection that's it so I want to connect to mySQL database here using from UI but again when you run this code it will create a DOT DB file for you this is my database and it is already in my local machine in my current working directory that's why it is my local path yours can be definitely anything else and then I want to say that create an Executor for talking with mySQL using openai temperature is one of the parameters with opening your models as you know and the toolkit is going to be SQL database toolkit database or it is specified on the top here and then start talking with my database so as of now whatever I'm going to ask from my database I'll say that hey agent execute this question this is sort of what I added in the chat here for example describe the playlist table but here you I want to show you the Chain of Thought that how these conversational based questions get to a SQL query and the result was back as a conversation so when I asked describe this table here's the action we're defining for open air model so it need to figure out first the list of the tables that you have got them actually and then the first thought this is actually based on the prompt engineering that line train team has done which is great so you can see the Chain of Thought the first thing is chat GPT is telling well I should look at the schema of this table if I want to describe this right so what is the action I want to check out the schema of that table for what table playlist track because the user asked it so it was able to figure out the schema of the table and even grabbing some couple of rows to understand the values of that and then the opening a model said okay I know the final answer the final answer is this this is what we saw in the UI as well right and here is a final answer let's ask another question here I want to ask describing a table that doesn't exist so that's going to give me an error but open your model will figure out the error result reason and resolve it for me so here again when I ask describe a table form it should go to list of all tables it will grab them and then it says that well there isn't there the table name playlist song doesn't exist but it realized that from the list of tables something close to playlist song exists which is called playlist track so then instead of through you the error it go back and check that table which was my intention but I put it wrong here and then it was able to actually retrieve the result back without showing me there so it recovered from another what else the same thing that we just run through the UI here I want to show you the chain of thoughts at least a total sales per country and then which customer spend the most so first it should say that okay I need to know the list of the tables that you have and which tables that I want well I think you need to I need two tables I am actually behaving like how Chachi video works based on your question I need the invoice table you're talking about sales and stuff and customer table because you're asking some customer customer that's why it understood that you need to query these two it grab this schema and then based on the most suspended stuff I need to do some queries and joining these two tables and there you go it was able to create this query for me do the sum and then join it with the key this this is amazing and it retrieved back all the results for me and it realized that USA the first observation got the highest sort of I think spent and that was the outcome we saw in the UI right so here are more examples included in the notebook show me the total number of tracks in each playlist the stuff the same thing it was able to go back generate the SQL query and the results is back here it said that the playlist name should be included in the results that's why the result has the playlist name as well or recovering from the error the same thing I'm gonna ask something that doesn't exist and it is able to recover that and give me back the results which artists recorded the longest track I actually added this last night and it was able to retrieve back the results for me or this one is actually funny I wanted to check if I want to do or plot or do something and even generate the output in a python code it work or not and it worked actually I said you know what plot the trend in length of tracks and give me the python code of it when I say python code I wanted to give me a python code that plot the trend length and what is the trend length open air should tell me then the same thing listing tables checking out the table needed which is track because I'm asking about tracks and then it was able to figure out for me the answer the trend limit of tracks can be plotted using the following code and not only it figure out the the track length values and also it's giving me the python code you can't see matplot there was a python code so I can if I run this in a python code later it will actually give me the the plot that is visualizing the trend length of tracks so that was just a simple walkthrough and a demo how you can start talking with your tablet data that I had in the sqlite but it can be a generic SQL database as well please please please uh I would love to have your comments questions and the comment side of the video so please do not hesitate to ask any question that you have or suggestions for any topic or if you see that for example there is a need there is a gap that you have seen But open AI models still cannot fix them write down in the comment section we can maybe figure out the solution for that together and come up with another video So based on your business based on your project I want to see still what what gaps you are witnessing that we can talk about them and potentially have more and more topic to discuss together so I would be very thankful if you like the video and put your comments to that and I always read all of them thank you so much for watching the video so far sometimes do something big for a stranger without any expectation for return [Music] dream big my friends believe in yourself and take action until next video take care [Music]
Info
Channel: MG
Views: 70,198
Rating: undefined out of 5
Keywords: open ai, gpt 3 ai, gpt 3, azure ai, artificial intelligence, machine learning, openai chatbot, gpt 3 fine tuning, openai gpt 3, gpt 3 prompt engineering, openai chatbot gpt writing code, openai chatbot demo, chat gpt explained technical, open ai chat gtp, Azure, Azure Open AI, ChatGPT in Azure, Open AI in Azure, word embeddings, chat gpt, advanced tutorial chatgpt, chatgpt advanced guide, GPT 4, SQL Data with ChatGPT, Chat with SQL using ChatGPT, chat gpt to make money
Id: 1FeBkAccobY
Channel Id: undefined
Length: 21min 30sec (1290 seconds)
Published: Tue Apr 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.