Build Your Own AI Chatbot: ChatGPT API for Beginners [FULL TUTORIAL]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video is the ultimate beginner's guide to using the brand new chat GPT API in order to build applications and build powerful businesses I'm going to be going through why this API is so important and such a game changer for anyone looking to build applications and build businesses within AI quickly going over the new documentation so you're 100 up to speed on how to implement this before finally showing you some examples of this API in action we're going to be building some applications on screen that you can copy and paste and steal for your own uses understanding this API in the doors that it opens up is crucial for all entrepreneurs looking to get into the AI space and build value this is without a doubt the biggest opportunity within AI right now and there are going to be billion dollar companies built in this rush so do not miss the life-changing opportunity that comes with this API release please watch this entire video you're going to learn everything and then afterwards you're going to be able to build your own businesses and change your life those who make it to the end of the video are going to be armed with information and skills that they need to not only build their own applications using this API but more importantly see the opportunities it presents as we know within this game it's not always the person who has the technical know-how to build it but the person who can see it and execute on it first so what is the chat GPT API and why is it so significant to us access to this API is a game changer for entrepreneurs and developers alike because up until now we have only had access to the raw llms that underpinch at gbt and not the Fantastic conversational ability that it has what this API allows us to do is to leverage the insane amount of work that openai has done and reinforcement learning and fine-tuning in order to take these large language models like DaVinci 003 and create chat GPT we now have our own Plug and Play chatbot interface that we can put into any application we want and finally the cherry on the top that makes this API release a complete game changer for us all is that it is 10 times cheaper than the previous DaVinci 003 models yes that's right 10 times cheaper and it's faster now us as a consumer and Builder on top of these platforms is the major winner in this AI race we're seeing right in front of us because this is a Savvy move by open AI to undercut the competitors in a major way so that they simply have no chance of competing and they're going to get all of the markets here as quickly as possible so thank you to open AI for being Savvy with the business move and giving us such cheap access to these apis to build applications on top of next we're going to be taking a quick dive into the documentation so that you can understand how they want us to use this and the kind of code that's required to implement it in your own applications so as you can see they say it's powered by GPT 3.5 turbo which is their most advanced language model they suggest that with this API you can do things like write python code draft an email or other piece of writing create conversational agents shoot it in a range of subjects simulate characters for a video game and much more as you can see this is just opening up so many doors that were not open before due to the limitations of the older apis here on screen we have the main point of difference in terms of using this API compared to the previous ones the main difference here is that we have this messages parameter which takes in a list of dictionaries which have the role and also the content so here you can see it has the role of system the role of user and assistant and then the content of the message because they're a simple solution to having some form of chat history and context to the conversation each time your user enters some information it's going to take that and add it to this list of messages say user and in their content and then when chat gbt API replies it's going to go assistant and then put the content that they have just written in there as well and then a little bit more information about how you can manage your tokens which we won't be going into within the scope of this video and one one thing to note down the bottom here is that fine tuning is not yet available for GPT 3.5 turbo but it likely will be very soon now we can jump into jupyter notebook and give you a few examples of how this API works and how you can implement it into different use cases now if you don't use jupyter notebook you can head to Google colab is a great alternative or whatever environment that you like to use you can use vs code Sublime Text whatever it may be you'll be able to achieve the same results firstly you want to pip install openai as you can see I already have it installed and then you need to import open Ai and set up your API Key by calling openai dot API key and then pasting in your API key now we have two different methods we can use to interact with this API the first one I'm going to use here is using the python library and we're going to create a quick chat bot using the API here now I want to make a quick thank you to one little Coda who actually wrote this particular while loop that allows us to create a chatbot so I want to give credit where credit's due he put this up on his GitHub to you so I'll put it in here for us to use as well now to start off we need to create our messages variable and include any kind of setup we want to do here so this is where you do all your role prompting all of your setup in order to get the right output out of the bot so now the first one needs to be a system role so we have roll system content UI kind helpful assistant pretty standard chat GPT like primer then we can take our messages and any kind of setup we've done and insert it into this while loop here which is going to be taking you to input appending the new messages and the API completions enter this message so it's keeping a running total of all the chat and all the context and then it's going to print out the response so this is all going to be available after the video for you to copy and paste over to your own Solutions what you can do with this block here is essentially just change the messages change this top part here insert any kind of setup you want for your Bop say you are a XYZ you do this as this and then you just insert it into this wild block and then you can start running your chat file and so what this is doing is calling the open AI chat completion that we saw in the documentation over here openai.chatcompletion.create and we've picked the model as GPT 3.5 Turbo now we're putting these messages right in here and here we have it working I've said hello and it's replied to us hello how may I ask a student do now here we can demonstrate the context and chat memory that this little while loop has and that the API allows us to work with as you can see here I've got I need help finding the right screwdriver sure I can help you with that what kind of screw do you have I can say it looks like a star and on its own me just saying it would never be able to work with any of the previous apis because it doesn't have any context me saying it they don't know what it is but because we've been talking about a screwdriver I can say it looks like a star and as you can see it's able to give us a response understanding what it is and next we have another method of calling this API which is using an API endpoint and the requests library and python again this is from one little coder thank you so much to him for whipping this up but this allows us to control a lot more of the variables we have the temperature the top P the frequency penalty Etc but it essentially works in the same way what we have is the completions URL that we want to be communicating with we have the payload then we have the headers as usual requests package implementation so here we have the messages in the same way you could swap out the messages into something like this create your messages list and then just insert messages into here if it's cleaner and so we can turn this temperature down to 0.1 now when you're using the API endpoint like this you actually need to include a row within the messages this is essentially The Prompt that you use to send off to the older apis but now you need to include it as role user and then the content is the question you want to ask so here I have a system message that says you are a kind helpful assistant who is five years old and now I entered the question that I want to ask the API which is what is the Empire State Building and now here when I run this cell you can see it thanks for a little bit and then it gets back to me with this big mess of Json here that you see now all we need to do is pluck out our answer here which is in the message content area but as you can see it's given us the answer which is the empire state is a very tall skyscraper Etc so this format allows you to use it as you'd previously done with the API endpoints which is including your message and it gives you back an answer now of course this is done by including the user message as a open-ended question that you post to it now this can actually be Illustrated a little bit better over in post band so I'll head over here and show you exactly how this works so here on screen we have a system message saying you are a helpful science teacher a user message asking the API what is the first computer in the world and we're able to send that wait for the response to come back and here we have all the information that you just saw over and Jupiter notebook but in a little bit of a nicer format so we have the content here the role so just saying this is chat gbt replying to the question now what we're doing in that wild true block that I showed you before is essentially taking this and adding this response into this messages body before we send it each time imagine that I put a comma here and then I pasted this whole row again and I changed this to assistant and then I copied the content of this and then I replaced it with this so now the response has been added to the messages that we send off to the next response so now I can ask a new question by copying this row again and then I can say how big was it now I can ask the API given this context what could it do and here in the content it's explaining what this particular computer could do now the same process repeats over and over and over again you take the content and the role and you assign it to another row within this messages list so what we were doing over in Postman is exactly what this while true Loop here does is it's taking the user input and it's taking the response and it's adding them into the messages list that you have and just growing that over time and every time you make a new request to the API it is going to take that list and remember everything that you put inside it so now that you're up to speed on what this API is what it does and how you can implement it now we're going to go through a couple examples just to show you the kind of options that you have with this API first example I'll give is a coding coach now this API opens up so many doors for specialized coaches because all it takes is a little bit of prompt engineering you can set it into a mode and you can create an entirely new service just with the correct prompt it's important to realize that anything that you were able to do within your chat GPT on your laptop on the website all of those things saved down the side your previous searches and your previous interactions with the bot that had saved as separate instances everything that you've been able to achieve in those all the modes you've been able to set all of the different outcomes you've been able to get out of chat gbt can now be replicated with duplicating those prompts into the messages and now you can programmatically access that for any application you want to build now everything that I had in that column which I'm not able to show me at the moment I could have created an application out of so what we have is this coding coach setup I have said a system message you are a programming tutor was helping the user learn the basics of python you need to ask the user questions to help them understand the language and give them challenges they must complete they can paste in their code for you to check you need to progress them into more and more difficult Theory and practical examples over time so I'm setting things up here telling it what its objective is it's supposed to teach them the basics of python ask questions get responses grade their work and slowly progress these people down towards more and more advanced at understanding python now one thing I will mention that is important to know is that in this current version of GPT 3.5 open AI has said that it does not always pay strong attention to system messages future models will be trained to pay strong attention to system messages but right now they don't necessarily understand or look at them enough so what I'm going to do is duplicate that system prompt as a user message as well just to be 100 sure it understands the setup and putting into it and then we can start the bot properly now for simplicity's sake I've taken that while true chat box block from one little coder and I put it into a chat function so all you need to do is pass it the messages you've created instead of having to repeat the code every time so just to clarify what you're going to see down here so as you can see I have the messages and then I have this chat function and all I need to do is pass in the messages so I've duplicated the system message into a user message so the same thing essentially but this is the user saying it this time so it really understands what I'm talking about then I've got the assistant to say yes I understand and so when I run it this is the output I've said hi I'm here to Learn Python my name is Liam this is what am I trying to accomplish I said start from the basics I know nothing sure thing let's start with the very Basics ask me a few questions and then it actually goes on with now now that you have an idea of what python is the first thing you need to do is install it on your computer have you done that yet or do you need help with that and now it's given me instructions on how to install python on my computer now as I go along it's going to start asking me questions about can you write this can you do this and I'll give it my answers back just imagine if you package this up into a nice looking UI and you put a website up and said Learn Python with a customized python tutor you could get this thing to start setting homework and teaching along and being someone's personal python coach over time this is just a simple example of the power of this API given the right prompt and you're able to plug this into a nice front end for people to have a look at and work with really awesome stuff another quick example here is a personalized email responder in these messages here I've given it four different examples of my own previous emails so that I can learn my style and how I respond so now that I've set it all up all I need to do is say can you reply to this email in my style saying thank you but I'm all booked out for this week and when I hit enter it's going to paste in the email from the person what I can do then is paste in an email that I receive or my assistant could do it paste it in there and get the response as you can see here it's replied to it thank you for reaching out and giving me a personalized one that seems to have matched my style of writing exactly now if you imagine this as an actual application you could say people sign up on a nice looking UI they connect their Gmail account you take all of the information from the sent mail and you take that and you learn from it you put it into the messages in some way and then what you're able to do is get them to Simply input their email that they receive and you instantly give them a response back in their style there's all sorts of different things you could do with this and you can imagine how this platform would look but again just a quick little idea that you could create an application out of and start potentially selling to people now my last example here is really leveraging the new ability from this API which is code writing what this prompt creates is a game developer tool it uses the power of chat gbt to take text and generate code by taking user input and then creating games out of it so I've written The Prompt here you are a game developer you generate Python scripts for games based on what people describe you and I've got a few more things in here hi I need you to help me create a game in Python I will describe the game to you and it you will give me back the script for it please be sure to always include code for a graphical user interface or GUI that appears for me to play the game on is that okay just asking for some confirmation from the assistant and then it replies yes of course please provide me with some details on this game and that is where the user input starts now all I need to do is put in the kind of game at once so I can write tick tack toe now this is going to go off and write me a python script to create that game now after a while it's given us back an entire python script that if I copy and paste it over we can see if this actually works now here is the entire tic-tac-toe game that it's just created for us and I can scroll down and run this now we have our GUI on screen here and I can start playing [Music] now it's obviously working correctly I can click on different parts of this interface and it's going to put down the right character this is just a very basic example of course but as you can see it's been able to create an entire game in just a few seconds of generation you can see where this will go potentially you can get it to do code completion of all sorts of different things but by having access to this code completion feature you are now able to essentially scrap together a whole bunch of different prompts in the most extreme case you could say build me this entire application and then what you could do is chain together all these different prompts and say now I need a backend that works with this now can you write me a basic front-end that connects to this and now we have the ability to connect up an entire web application potentially using this code completion feature that about wraps up for the tutorial guys thank you so much for watching I hope you now are confident in your understanding of the chat GPT API I'm going to be dropping all of this code in the description below so you can pull this up start playing around with it check it out use this code block that one little go to created and start to play around with writing different prompts and pre-loading different messages so that you can turn this into different sort of applications there are so many doors open by this opportunity that you have to start moving on it now or people are going to beat you to it the gold rush for companies built on the back of the chat GPT API is happening right now and before you know it it's going to be completely saturated and filled out now if you have an idea and you want to bring it to reality and you think you really have something special then please you can get in touch with me as a consultant I will help you talk through your idea and figure out what's good about it what the feasibility is but I can also help you a step further with my own development team so if you're looking to actually get it built out into a platform so that you can start building your first AI SAS AI startup then please hit down below both links will be available for you to get in touch with me down there if you have enjoyed the video please hit down below and leave me a like And subscribe for more AI entrepreneurship content I post at least three times a week so if you're looking to upskill in the area and you're looking to build value as a developer or entrepreneur in the space then this is the place to be hit the Bell so you don't miss the next one and subscribe to the channel anyway that about wraps up the video thank you so much for watching and I will see see you in the next one [Music]
Info
Channel: Liam Ottley
Views: 5,693
Rating: undefined out of 5
Keywords: chatgpt api, chatgpt api tutorial, chatgpt api python, chatgpt api key, openai, chatgpt api php, chatgpt api postman, how to use chatgpt api, artificial intelligence, chatgpt tutorial
Id: YCBIZ0L1axc
Channel Id: undefined
Length: 17min 16sec (1036 seconds)
Published: Fri Mar 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.