Learn the ChatGPT API (GPT-3)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
everyone and their dog has tried out tattoo GPT and is playing around with it it feels like the future that people were talking about years or decades ago is happening right now but if you've never heard of it before then here's a quick overview of what this tool is about chechi Pichi is a chatbot developed by openai and was released about a month ago in December the chatbot is powered by gpt3 which stands for generative pre-trained Transformer it's a neural network machine learning model that is trained with tons of data from the internet in fact it's actually the biggest one ever made with 175 billion parameters and is optimized to generate human-like natural sounding answers no matter the subject like anything literally anything now that's cool and all but what's even better open AI actually offers an API that lets you access gpt3 and use it for whatever you want that means you can integrate it into your website or application or you can create a new service from scratch around the API in this video I'm going to show you how you can get an API key how the API works and we will build a little website that uses the API also make sure to watch the liand because I'm going to share an important Pro tip when it comes to using the API so with that out of the way let's get started the first thing that you need to do is head over to openai.com API click on get started and create an account next go to beta.openai.com account slash API keys and click on create new secret key make sure to copy and save it somewhere safe because you won't be able to view it again now that you've got your key let's put it to use for the sake of this video I'm just going to quickly set up a react website using veed but you can of course use whatever framework or programming language you like I went ahead and removed all the boilerplate and as you can see we now have a blank page before we get started let's quickly add some basic CSS to protect ourselves from eye cancer much better the first thing that we need is the user input so let's create an input element and save the input whenever the user types something if we display it we can see it works now that we have the setup let's create a function that sends the user input to open ai's API to get the response you can either install openai's npm library or you can just directly send the API request if you're using JavaScript then I'd recommend using the library but for the sake of this video I'm just going to show how to make a normal API request just plain and simple so let's make an API call using fetch first we need to provide an URL which is api.openai.com V1 completions and for the second argument we need to pass out an object with options first let's specify the method as posed then set the headers with the content type as application slash Json because we're gonna send some data and for authorization we need to put in Bearer and then your API key that we created in the beginning now we're getting to the interesting part which is the body of the request here let's create an object first we need to specify which model we want to use gpj3 has actually various models that you can choose from text DaVinci 003 is the most capable one and is all purpose but is also the most expensive offensive one the other remodels are more optimized for specific use cases and cost less let's just choose the normal DaVinci model next we need to give it a prompt this is what you would enter for example in chatterjpt let's add it to the user input and now we can also set something called the temperature which can be a value between 0 and 1 and controls how risky or creative the answer should be zero means it will go with what it thinks is the safest answer this also means if you give it the same prompt multiple times it will always give you the same answer if you change it to 1 it will produce more creative and riskier answers which could be worse or better it really depends on the use case let's set it to something like 0.3 now let's await the response and use the Json method to unpack it then let's lock the response and see what we get the only thing we need now is a button to call the function let's try it out water is a funny dog name and this is what we get to find our answer we need to do a little bit of digging first go to choices which is an array open the first item and our answer is here where it says text and let's display it for that I'm gonna create a new state called answer and set it to what we receive in the response and then display it like this and voila that's actually pretty much it now you can use the API and build whatever you want but now you may think hold on if there is so little you can adjust in the request then why would anyone want to use it compared to chatterjpt well you can make it easier or more convenient to access it by creating an extension or integrating it in an already existing service so that the user doesn't have to always go back and forth and the second reason is that creating really good prompts is not that straightforward if you have a specific use case and know how to create good prompts by for example providing a lot of context and even answer examples or templates you get the best possible results not everyone knows how to do that or to do it well in addition to that you can create a nice interface that makes it easy and guides the user through the whole process of creating the prompt like for example this code explainer page that I built for testing it creates a good prompt by making the user put in the programming language and the desired length of the answer of course you could add more input options to guide the user and create an even better prompt now before you head off and build the next AI startup you need to know something important about the API if we go back to the response you can see it contains a property called finish reason which says stop that's good because that means it finished naturally and you could expect the answer to be complete now let's try to give it a prompt that leads to a longer answer the answer this time is pretty short and not complete if we check the finished reason it says length that means it couldn't finish the answer that is because every prompt and answer consumes something called tokens if we check our response again you can see that under usage it tells you how much Tokens The Answer costs it how much the prompt cost it and the total cost open AI charges on a per thousand token basis one token is equivalent to roughly four English characters so one to two sentences are about 30 tokens a paragraph is roughly 100 tokens and thousand tokens are roughly 750 words open AI has a tool called tokenizer where you can quickly check that as you can see by default the max token amount is set pretty low and that's why it couldn't complete the answer if we set it to a higher value in the request body then we get the full answer that we expected thanks for making it to the end of the video let me know in the comments what you will be using the API for thanks for watching and I'll see you guys in the next one
Info
Channel: FrontStart
Views: 3,938
Rating: undefined out of 5
Keywords: ChatGPT, Openai, AI programming, ChatGPT programming, ChatGPT coding, ChatGPT API, How to use ChatGPT API, OpenAI API, Chatbot API, ChatGBT API learn, How to use ChatGPT, Create website ChatGPT, Integrate ChatGPT, GPT-3 API, GPT3 API, GPT3, How to use GPT-3, Learn GPT API, AI programming tips, ChatGPT development, ChatGPT application, ChatGPT React, Use ChatGPT in react, GPT3 with React, ChatGPT react app, OpenAI programming, GPT3 for beginners, GPT learn, GPT react
Id: gRoNpP4dFMg
Channel Id: undefined
Length: 6min 29sec (389 seconds)
Published: Wed Jan 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.