How to Use ChatGPT API - Create Your Own AI Apps Beginner Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
was good everyone so today I'm going to show you how to build your own applications utilizing the chat GPT API this is going to be very beginner friendly super simple to help you get started and then from here you can go ahead and create whatever application you want to so first thing is how do you even figure out where the API is and well if you search it it can be a little confusing but all you need to do is go to platform.openai.com then you need to log in with an account if you don't have one make one and then from there you can go to documentation and they do have a quick start tutorial which is fairly simple and easy but what I'm going to show you is actually even easier to follow along and start from scratch however they do utilize their own built-in functions for the API which essentially saves you some code but if you're just starting out it can be quite confusing to understand so what I'm going to do is show you how to essentially start off from scratch and then you can build out your own apps that way however if you do want to follow on the docs you could go here have no install if you don't go and do it there and then you can clone this or simply download this file from the GitHub and this essentially their starter application but I'm gonna do it even easier method and I'm gonna make this from scratch so let me let me just bring this up real quick and I have vs code as my code editor so let me go right here and let's just go ahead and let me yeah let me bring this one over so we can have like a half screen that way we can see the actual uh docs at the same time and we will need this again to get our API key so I was testing out earlier with a bunch of them but uh pretty much here I have an empty vs code window so what I'm going to do is type command J to open up my terminal control J windows and right now I have zero folders files whatever created so if you want to create your own go ahead and do that but I'm just going to go ahead and say CD into desktop first because I want to save this on my desktop then I can say mkdir and let's just call this the Chad GPT API app dash one so I'm just making a folder now called this that I can CD which navigates into this folder I just called chat GPT API Dash app dash one whatever you named your file you would CD into that press enter and let me just do code dot to open this up if you don't have this set up you can just uh basically you can just open it up on your actual computer too but let me just bring this over and now let me yeah let me get off rid of this previous window I don't need this now we can have some fun so first thing is this is going to be a very basic template if you want to see a more detailed application definitely comment below and I'll create one after this but for now I just want to make something very base template that way if you want to make your own thing you could do sort of whatever you want because a lot of other apps they have like specifics and it's kind of hard to understand so first off let's go here and let's just make index.js and again if you do not have node installed just go go download No by just Google searching or you can go through the API install node right here too and this is going to be our basic uh file we're going to do a bunch of coding in so first thing is we have to install some packages so let's go to terminal command J again and we need to install uh open Ai and I want to utilize axios you could use fetch to or give you straight up their uh API functions as well and then we're going to need to install a EnV as well so first off let's just do npm install and I'm saying axios M say open AI and then I'm going to say dot en so let me drag this over a little bit you can see what exactly what I typed and I think from now this is all I'm going to use for this setup but we need more we'll install it later no big deal but here this will create a package Json file we got axios.mv and we can open AI so now what we need to do is write out our code so if you want to actually follow along with the docs we do need a secret key which is right here so in order for us to access that the way I'm doing it is creating a die in V5 so if you've done API for you pretty much know this but basically they even have notes Here you you essentially don't want uh to people to see this so the way you can do this is you click new file here.enb enter and then for the name this is what you do whatever you want to do I'm just going to call this open AI capitalize by the way underscore API underscore key press equal and then what you need to do is go to create new secret key if you don't have this you can also click here and go to the your API keys but I'm just go here and create it and already have the memory Keys No so let me delete let me delete some of these so I'll delete this one delete this one and also yeah if you have too many you don't need them you can just delete them so I'll just click create new key and I'm brother this out obviously but again just make sure no one sees this for tutorial sake I could just revoke this afterwards so no big deal but again paste this in I'll paste that hit save I'll switch over now so you can't see what the key is but basically I paste that in and now I have it in my EMB file so now we need to call Api and then have some sort of code written for us to do this so there's a couple ways so right off the bat they have their own code blocks and their templates so if I were to drag this out over here a lot of it is actually in Python too so again if you're using python perfect but uh go here to API reference and again we've already installed opening eyes we don't have to if you're using python obviously you do pip and then this is the setup here and then they use kernel and obviously they have a different set of code but here's like their built-in functions for the API so that way it saves the essentially saves you from running out the code but again if you've never coded before you're still new this is going to be like super confusing so I'm gonna do it from using axios essentially from scratch and one cool way to do is you can actually just go here copy this and this again this is using python right so you can go here and say rewrite I'm on chat DVT by the way we write this in axios paste this here and this is one way to do this also if you were ever to use um actually again it's fairly simple anyways to set this up and they separated everything too that way you can just call it in you can do it with the inside as well it doesn't matter but again this looks like it's working so I copy this here and let's go back open the eye again you can write this from scratch and there's different ways I had this written too but uh just look at the code real quick and see how it looks so first off we have this URL that's where we're gonna have everything and if I were to go ahead and save this it's not going to work so we need to do first off is go to authorization we need to let's go do backticks also you can do um codes as well let's do back ticks and then for your API key let's close these on bad ticks first and then I'm gonna do dollar sign curly brace and I'm just going to call this I'll delete this completely just say API and then key like this you can name this with literally whatever you want to but keep like that and then we could say const and this is the variable name API key which we just put right here and I'm going to say equals 2 and then you would do process.env dot open AI underscore API underscore key and you're probably like what is this part well if you ever use uh diamb you know this is what you have to put in front of it and then again on a DOT EnV file this is what exactly what we named it so make sure you save it name it like this so you want to hit save and then I go here and just type in node index.js it's not going to work it's going to cause an error and then go crazy and you see a bunch of this code right here and pretty much if we scroll enough it should show the actual API key it should be undefined and let me see if I can find where is this tell me if I just go here and just do like console.log and be like yeah is the API and then I could say API key don't worry about this it's just for example tutorial say if I were to just go like this and uh let's just erase this let's just say Hi and then here because I just wanna I wanna save us view so we can see what's happening so it's going to say API undefined so right now it's saying it can't read the API key and that's because we have not actually imported some stuff at the top so in order for us to actually read the API key we need to write in some code so already do is say require parentheses quotes dot EnV and then outside we can say dot config parentheses hit save and now if I were to run this it would technically show the API key so I'll probably have this blurred out but uh now you can see up it shows the API key there and it says hi which means it's logging this response here so now I can just go here I can change this to error now and then I can change this to uh whatever we want so I'll say response and right now we got to find what we want to actually post now so let's do it should be response to that data and then what happened to my oh yeah there we go okay so let me log response.data first I want to see what is actually showing up let me get rid of this API here so again this is what the code looks like currently and again if you want to have this import we can also update that to import but if you were doing Imports you had to go in here and type in uh like type and then change it to uh module but uh yeah when I do that for now we don't need to but if in case you want to and then we'll just do node nhjs and I want to see the data that shows by alright so now it says here created model choices object here okay so what I want to do is go response.data dots and let's do choices and I want to Target the first message we're going to put dot zero and then I'm going to say dot message and then dot content so let's try this see what happens I'll post no the index.js and look at this it says it is a test so what's cool here is we can say uh we can update this and also this is the model which I'll go through in a second but uh you can say like what is two plus two save it and it's going to respond in a terminal with four ideally this is correct there we go look at that so real quick I'll show you guys what this part does is the uh the model if you were to go here they have different models so this I think is the most recent one the gbt 3.5 Turbo I think that's the most advanced and then they have like one exactly just for Tech so Tech DaVinci 03 there's another one I don't remember exactly how I wrote it let me see if I can find it but basically this these models here's gbt 3.5 turbo game you can go through the docs and look through different models and again depending on what you need you would obviously update this and what's even cool here is this is again just showing you the basics of how to set it up because then obviously if you want to sell this on like a website front end you'd have to create your own front-end parts and then and put these values through there so we could say like write a 100 word script for a I don't know a scary story and then this essentially if you were to have like a chat uh log you could type this type of script in and you can change the content up to but basically I just note in the Js and what's gonna happen now is actually gonna hopefully write this script in a terminal which ideally if you understand how this is working then that means you can go ahead and create your own front-end parts or you know download some packages and then pass those values in to where this will display on your actual desktop AKA your website browser so right now it's loading because it's going to take a minute well I said 100 because I did before and it took like it wrote like an insane amount of uh lines so let's see getting air open eBay what happened here let me see did I put any uh undefined maybe something happened so let's do this instead of putting uh 100 let's just say write a script for a scary story so again since this is still basic I didn't want to keep it too crazy message content yeah I'll keep it like this for now hopefully this uh prompt works but uh right now let's try to look at I can see if there's any noticeable errors right here and let's see let me go up here and see opening alexios so make sure I have yeah maybe looks like it's I don't think that would be the issue maybe it might have been a prompt I put but now let's just see what happens when I type this prompt in and then see what happens so now it's still saying an error yeah so it should it should work what if I ever let me close that really quick clear note and there's a JS again should be working I'm not sure why isn't working right now all right there we go so yeah I guess I just cut a closed server I'm not sure why it was giving me the air earlier because like I mean I didn't see any issues with the code but yeah so look at this now we have this uh scary scripts written it out and it's very similar to how China beats would have been if you would have make this on your actual uh web page so again I'll do like one more example I don't know let's see um tell me 10 foods that are healthy save it again write it out and we'll see if it actually does continue to work yeah so I I knew this so there was anything wrong with the code it was just weird I guess it's not working but so far there we go we have 10 lists right here and actually has explanation so as you can see this is a very basic setup but what you can do now is create a front-end section you could probably move this code into like a different file and then basically go to the docs and see like their specific type of project you want to build and then utilize that from there any of these seos you use their built-in for just two or in Fetch whatever but this is pretty much the very Basics on how to use Chachi BT API if you enjoyed this video be sure to like And subscribe and I'll see you in the next one
Info
Channel: Brian Design
Views: 6,863
Rating: undefined out of 5
Keywords: chatgpt, ai, chatgpt api, how to use chatgpt, api
Id: RlGrI764hD4
Channel Id: undefined
Length: 14min 44sec (884 seconds)
Published: Sat Mar 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.