Creating a custom GPT-4 Chatbot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign I'll show you how to create a custom gpt4 powered chatbot that can respond to tweets questions really any textual data and in any format or personality that you like so you can create a fully custom chatbot here that is fully your own and is completely different than anything that I might make or anyone else watching this video so let me give you a quick demo of an example of a live chatbot that's kind of using the strategy that we're going to deploy in this video and you'll get a sense for what I mean so you can see that there's a Twitter account here called snoopsteen now this is a chat bot this is not someone actively running the account and anytime you tweet at this account or hashtag the name so snoopsteen it automatically responds to your comment now if we look here we can see that we have some tweets so for example you can see he's responding to someone dear whoever tweeted at him yo listen up it's time to Feast whatever this is jakarti Munchen on a Chick-fil-A a mini breakfast Beast Etc I'm not going to read through all the tweets they're kind of funny but this chatbot is in the kind of personality of Albert Einstein combined with Snoop Dogg so you get the knowledge of Einstein but kind of the rhyming and responses that Snoop Dogg might have and this is just a very simple example of the type of chatbot you could create you could do ones in different kinds of personalities you could have ones that are answering as if they're living in like the 1500s or as if they're an alien you can do really interesting stuff here obviously you don't have to host it on Twitter but if you want to mess with this existing chat bot then just go to this Twitter account at Snoop underscore Steen uh tweet at it or hashtag the name and then it will actually automatically respond to you within a few minutes all right so that's kind of an example of what we're going to be making again you could host your chatbot wherever you want once you have it it's super easy to use it and you can kind of put it in any format that you like so before we go any further I'll quickly mention that I'm going to be following this guide right here which is actually people that created the Snoop Stein chat bot this walks you through everything you need to do to create the chatbot as well as to host it on Twitter I'm not going to host on Twitter in this video but I'll show you everything in terms of getting the chatbot up and running using the chat bot querying the chatbot responses and then you can deploy it how you see fit so if you want to follow the guide click the link in the description and now let's move on to step one where we start creating this bot so for this video I am going to be using a platform called mindsdb now mindsdb allows you to import your existing data into their platform and train machine learning models quite literally in the matter of seconds using SQL syntax now I'm going to explain more about how this works but I do need to disclose that I am partnered with minesdb they have sponsored this video however this is completely free I'm not trying to sell you anything this really is just a revolutionary platform something that I've never seen before and I wanted to show it to you guys because I know you can get a ton of value and very quickly actually use AI models that before might have been a bit intimidating to you so with mindsdb as I was saying you import your data and then you write some SQL syntax which I know sounds really strange I'll explain that to you more in a second that actually creates what's known as an AI table for you now this AI table acts just like a normal database table and allows you to use normal SQL queries like select whatever field you want from this table to get predictions and to use your machine learning model and then you can connect to the SQL database just like you would connect to any other SQL database and use it from a front end from a back end from any kind of project that you want which I'm going to show you later in the video so if I scroll down here you can see that this is what's required to create a model create model sentiment classifier predict sentiment using this engine task model name input column Etc that's it you just pick the model you want already built into mines DB it will then train based on the data that you pass it then you will have an AI table and then you use that AI table to make predictions here if we look at time series again you can see obviously we can adjust the different input data and different parameters for the model you can get as complicated or as simple as you want but I'm going to show you that we're literally going to make this gpt4 model in like two or three SQL statements now obviously you can integrate with all your existing data too if you're not making a chat bot you might be making something else so like you know MySQL Oracle open AI you have mongodb really any data source even Google Sheets you can kind of import into mind CB and start messing with all right so that's enough of kind of the explanation of this platform let's dive in the first thing we need to do is create an account so I already have one I'm just going to sign in for you guys just go to this website mindcb.com create a new account and then you'll be brought into this Cloud editor where we'll start working alright so after you've created an account and gone through the setup steps you should be brought to a page here where you have a demo instance now I'm going to click into mine here obviously you can create other ones if you upgrade to Pro but you don't need to do that for this video and you can see that you have kind of a built-in SQL editor here and I'll zoom in a little bit just so it's easier to read we can get rid of kind of the Learning Hub on the side now this is where we can write all of our SQL as well as connect to different databases and start creating our models so on the left hand side you can see that we already have two databases we have the mycb database and then the files database which doesn't have anything inside of it currently which is fine now what we can do is connect to different data sources by going to add data and we can connect to mongodb mySQL postgres etc etc there's a ton of different data sources we have access to and then we can add different machine learning models here if we want now we're not going to do that that's a bit more advanced what we're going to do is just use existing models here alright so the first thing I'm going to do here is just show you how to create a basic machine learning model then we will continue and improve it and make it better so I'm going to paste in a block of code here I'll look explain this to you but feel free to pause the video and type it out or you can go to the link in the description for the guide that I'm following for this video and it will have this exact same code so it says create model mindcb.gpt underscore model we're predicting a response so that's kind of the output column we're going to get using the engine of openai the model name of gpd4 and then the prompt template now the prompt template is essentially telling us what kind of data we need to feed to the model when we're making a prediction and how we're going to respond to it so we're saying we want to respond to some kind of text which is a variable we're going to have to pass when we make a prediction by the author username which again is another variable very very simple I'm going to show you how this works in one second for now though let's simply run the code now notice here that you don't have to pass any API key or anything like that by default when you're using this demo instance it's automatically going to have an API key for openai for you which gives you access to gbd4 which is currently under kind of early release so you can see here that we get GPD model openai myzb we can see that it's currently generating and if we want to check the status of this model then we can type in the following line I think I'm just going to have to fix this a little bit so select asterisks from minesdb model where the name equals GPT model if I run this then notice that I get the status is complete okay so I'm just querying essentially the model we just created now if we go here to minesdb this database you can see the inside of here we now have an AI table which is our GPT model and now we can query this GPT model just like we would query any normal table and we will be able to get a response from it so to do that we're going to use the following line let me copy this in here so select response from mindcb.gpd underscore model where the author username is equal to mycb you could obviously change this maybe we'll do Tech with Tim and the text is why is gravity so different on the sun again you can change that to whatever you want and you're just going to get a gpt4 generated response so let's run this and we can see here that it's going to take a few seconds this is because right now open AI is heavily rate limited so it could take 10 20 30 seconds to get a response obviously later on this should be faster if you pass your own API key it should be a bit quicker than using the default one regardless you can see that we've queried the response right selecting the response so now we get a column which is our response and it says gravity is so different on the sun compared to Earth blah blah blah blah I won't read through it but this is the response we got for this query okay so hopefully that makes sense but that's as easy as it is to create a model and then use the model by selecting from the table again we're selecting the column that we want there could be multiple columns in this case it's just one from the mycbgpt model where and then we pass the two variables that we required in that kind of prompt statement okay so that is the basics on how mind CB works again I'm sure that this is not quite Crystal Clear yet but as we go into this next example you'll see how we can make something a bit more custom So currently we have a GPT model but this is not really chat bot ready right it's just giving us whatever response would happen from open AI we want to have a more custom model that has a personality that's speaking in a certain tone of voice Etc so let me copy in a new block here it's going to create a more custom model for us and I think I need to just fix something here with the quotations okay so let's make this a bit smaller so we can read all this we are saying create model mindsdb.snoopstein model now we can rename this but this is the one that was used in the guide so I'm just pasting it in for right now again we want to predict some kind of response using and then the engine is equal to open AI the max tokens is 300 which is the max number of kind of input that we can give to this uh this model then we can have an open AI API key again we don't need that there'll be a default one provided to us we have the model name and then the prompt template now is different The Prompt template is essentially what we're passing two open AI when it's going to make the prediction right so it's going to take our input message which is the text from the author username and then whatever we describe here it's going to do so in this case we're saying in less than 550 characters write a Twitter response to the author username in the following format dear at whatever the username is respond a rhyme as if you were Snoop Dogg but also we're as smart as Albert Einstein still explain things like Snoop Dog do not mention that you are part Einstein okay so there you go this is giving the description for The Voice or like the tone of the AI so we can change this and we can also make it so it's not necessarily responding to a tweet maybe we want to respond to a website message or something else right so you can kind of adjust this however you want so give me one second I'm going to write my own kind of custom prompt here and then we will continue alright so I've just written a new prompt here where I say respond in less than 150 words to the text from the author username in the following format greetings whatever the author is respond as if you're an alien from the future that is wiser smarter and more intellectual than the person asking you a question openly judge the stupidity of the question and mock the person asking it make sure to still give the correct answer do not swear or be inappropriate for the YouTube video now I'll actually change the name here to be the alien model I thought this would be kind of funny but you get the idea you can kind of create whatever type of Bot you want by writing in how you want the bot to respond or what you want it to do you can be asked creative here as you like so let's run this and you can see that now we're going to start generating this model again if we wanted to check the status we could select it so if I go here select asterisk from my CB model right so we could copy that take this and paste it in and notice here that it's going to tell us the status let me move this up a bit and the status is complete so now let's ask the model the exact same question that we asked the other one and see what kind of difference and response we get all right so I've just pasted in the query here let's run this and see what response we get here from our alien model all right so we've got our response here feel free to read through it I'll just read the first paragraph greetings some user oh how quaint and primitive your understanding of celestial mechanics must be is quite amusing really nevertheless I shall Enlighten you on the matter feel free to keep reading but already we can see that it's kind of got the gist of what I was asking it to do and now we have a custom chatbot alright so now you might be wondering how do we actually use this chatbot well if you've continued with that guide that I've Linked In the description it's going to show you the steps to actually deploy this to Twitter now I don't want to put this on Twitter because I don't want to chatbot running on my Twitter I don't want to make one you guys can do that if you want there's a few steps again from that guide but I will show you now how we would say get some different tweets and then use those tweets to generate responses so we're going to essentially join this um kind of query with all of the different tweets or different textual things we might want to respond to to get multiple responses at once so I'll show you that and then I'm going to show you how we can use this from say a python script so you can actually get outside of this kind of mindsdb editor and still be able to use your trained model alright so first thing I need to do here because I want to show you how we connect this with Twitter is I'm going to create a new database and this is going to contain all of the tweets from the mindsdb Twitter account that's just because we're in kind of the demo instance so it automatically has authorization for that if you wanted to get your own tweets then you would have to connect to Twitter by going here to add data and you have to give like read access I think from a Twitter developer account it's a bit more complicated again and it's kind of mentioned in that guide I'm not going to run through it in the video because I know a lot of you don't want to do that where you can't actually follow along with the steps so I'm going to say create database from my Twitter with engine equals Twitter okay let's do that so now you can see we have our Twitter database now that we have that we want to view a bunch of different tweets now I'm just going to use the query that the guide has here and what this essentially does is select all of the tweets that mention the snoopsteen bot okay so this is exactly what they did to make that bot they said select the ID created at author username text from my twitter.tweets which is a table we have inside of here where the query is equal to and then this is a query that you can write based on the Twitter API again not going to get into that too much essentially we're querying looking for any of these ads or any of these hashtags and the fact that we have some retweet we're also going to make sure that this was created after this date and we're limiting the result to 20. so if I run this here uh we get a bad request start time must be after this date okay let me just change this to be one day forward and notice if I make this a bit larger then we now get a bunch of tweets gives us the time they're created the ID the author username and then what all the tweets are and they all have the at snoopsteen um what do you call it filter applied to them right so we're only getting those ones okay so now that we've gotten all of these what we could do is join this response or join this result with our model table and then get a response to every single one of the tweets that mentions this button so let me show you how we would do that all right so I've just pasted in another SQL query here notice that we're just selecting all of the stuff that we need from our Twitter uh our tweets table we're calling this table T by the way that's why we have that here we're then saying join minesdb dot in this case it's going to be our alien model because that's what I called it if you change your name you would change it here and since we're using the Mind CB Twitter account I'm just going to keep this filter so we're going to imagine that anyone who tagged snoopsteen really was referencing our alien bot here and I'm just going to change this created that date to be 22. for some reason we need to um we can only query tweets within like the past week which is why we need this and in this case I'm limiting the number of responses to four so again we're joining two different tables so we have the one table that has all of our responses or sorry all of our like original tweets and then we're gonna join that with a query to our AI table which will then generate all of the responses to all of those tweets so let's make this a bit larger and let's run this it's going to take a few seconds to get all of the results here uh just because again open AI is like very heavily rate limited right now and it can be pretty slow alright so finally we have generated some responses you can see that we have the input text here so for example sub4sub YouTube channels follow for follow and then it comes here greetings Earthling obviously it's our alien bot now and it goes in and responds so I think that's pretty much all I needed to show you in terms of creating the AI model using the AI model now what I want to show you is how we get outside of this platform and use this safe from code because this is great and all but if you wanted to deploy this somewhere obviously you need to hook into this model and use it from some kind of front end or back end or wherever it is that you're going to use it so what I'm going to do now is open up a python file and show you very quick quickly how we can connect to our instance here and use this AI table that we've generated all right so I've just loaded up a python file here I've already written the code just to save us some time you can see that what I'm doing is I'm using my SQL connector now this is a module in Python that allows you to connect to a SQL database I also am then loading an environment variable file just so I don't share with you what my username and my password is but notice that all I need to do is have information about the host which is my cloud.mycb.com my user which is simply the email that you use for your mysdb account the password same thing it's the password that you used and then the port which is always going to be 3306 then I create what's known as a cursor object this is just how you execute queries when you're using the MySQL library and then I say cursor.execute and I execute the same SQL query that I did on the cloud here from python so select response from minesdb.alien model where the author username is mycb and the text is who is the best YouTuber now you can put whatever text you want here and obviously you could dynamically generate this and create like kind of a chat bot prompt here in your terminal if you wanted to do that then what I need to do is Loop through my cursor because it's actually an iterable object you can parse this in a few different ways but for now I'm just doing it very simply and it's going to give us the response so to prove to you that this works I'm gonna go here and run my code Python main.pi and you'll see that in a few seconds it's going to generate a response for me based on this prompt who is the best YouTuber so there you go we got our response greetings earthlings my CB your inquiry about the best YouTuber is quite amusing as it demonstrates the limited scope of your intellect and our Advanced future we have transcended Such trivial matters however I shall indulge your primitive curiosity the concept of best is subjective and varies from Individual to individual blah blah blah you get the idea farewell Earthling so obviously you can read through this response on your own you can parse it you can do whatever you want with it but the idea is that now we've gone from the cloud to our actual code I've shown you that in what 18 lines of code we're able to actually connect to that AI model query it and use it and even though we might not treat that as like a production model it's pretty close for what we're doing here so with that said I think I'm going to wrap up the video now obviously what I showed you is really just the tip of the iceberg when it comes to using mindsdb and creating machine learning models you can do all kinds of amazing stuff with your own data on my CB like regression classification more advanced models predictions anything that you can imagine you can pretty much create on there they have all kinds of very easy to understand documentation and tutorials directly on the website so I encourage you to follow along with those I hope you guys enjoyed this video and you got some knowledge and value on how easy it is to actually use stuff like open Ai and gpt4 and how you can take advantage of that in your own projects if you guys enjoyed make sure to leave a like subscribe the channel and I will see you in another one [Music] foreign
Info
Channel: Tech With Tim
Views: 50,317
Rating: undefined out of 5
Keywords: tech with tim, chatgpt-4 tutorial, gpt-4 technology, artificial intelligence, ai-powered conversations, chatbot development, ai chatbots, api integration, conversational ai, openai gpt-4, interactive conversations, target audience, ai applications, chatgpt-4, language model, chatgpt, dynamic responses, user feedback, mindsdb
Id: SWd_KU70C0s
Channel Id: undefined
Length: 20min 19sec (1219 seconds)
Published: Tue Apr 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.