How to Implement ChatGPT as a Chatbot in Python Using PyCharm IDE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys so welcome to this tutorial on how you can use chart GPT as a chatbot in Python using the pycharm so we did a lot of things to to install first you need to have a python running on your computer and you also need to have installed pycharm that will proceed to install the open AI with the open AI we can import it to use the um API so if you don't have python installed you can just go to python.org visit python.org you'll be able to install the latest or python release on your device I already have python running here so I don't need to do that so you can see the latest python as of the time of recording this video is 3.11 3.11.1 so you have that so when you're done say then you also have to download python python is an ID that you can use to write um python code so you can download pycharm when you go to jetbrains.com and you just jailbrings jetbrains.com download you'll be able to download um the you have to the two version of the pattern you can download professional and the community the professional has a lot of other features but it is not free but you can just download the free version the community version the allow you to write about our codes in Python so once you have that so I'm going to launch my however I already have a python and python running on this computer so I'm going to show you so this is my pycharm so um one thing you you can go to the timing out of my time if you go to the terminal so there's this down arrow here when you click on this down arrow select command prompt from here you can check the version of python that you have installed on the machine if I type python dash dash version so I have python 3.11.1 so now the latest release I have there I can also check um the because and another thing you need is you need pip because pip allow you to install um packages on your diet that you can use that that you can use the python and find charms so if you don't have peep you have to go to Pipeline and also to install pip so you can also check the PIP version here as well and most cases the PIP also come bundled when you install python as of python trip I have version of python I think people pre installed it so just you just have to check to be sure type pip then version okay so for me now I have version pip 21.3.1 so I have Python and I have peep installed so we're going to be using the PIP to install the open AI API so now because what I need to to be able to use the charge DVT API I need to be able to import the open AI package so if I just type in import open AI open now you can see I'm having an error here so you just have to increase this for you to see all right so you see that there's an error here so what you need to do so just trying to increase the font size okay all right so if I import opener you can see opener is installed and python is completely interpreter is saying that uh let me avoid it answer the message there so you're saying that no module name open AI so we have to pip install open AI so the PIP install open their eyes um just make sure you're connected to the internet to be able to do this so peep install so I'm going to say pip install open AI so press enter all right you see I so let's really installed open AI 0.2 6.4 so now I have picked installed on my computer so if I import open AI now all right you see no error now so we have open AI installed now on the system so we cannot go ahead and so if you go to the documentation for uh chat gbt so if you go to the documentation for chart gbt so if you go to open ai.com um at the top here you see API so here read documentation you'll be able to um see how you can use the open AI API in your code to do a lot of things there are a lot of things you can do you can check code with it you can also do text editor you can do completions and a lot of them so you open the API you can apply to virtually any tags that involves understanding or generating natural language or code so and if you look at the documentation here so we have some parameters that we're going to be using like the prompt the completions the tokens virtually um the way the charge that the the language model is able to understand um text is it uses tokens meaning almost everything is being tokenized so it has a tokenizer tool that allows you to understand a particular language so it's going to break it down for example if you have um the word hamburgers or the hamburger broken down into about three tokens ham is a token bur is a token and the gr guy is a token so that's the way it's able to um perform its prediction um accurately so and there are there are guys and there is uh open AI that you can see if you go to test completion code completion but you need to sign in so if you don't have an account with open AI just um or just query the openai.com and then um sign up once you sign up you have access because one thing we need that that we need to use in the open AI API is the API key so the API key is free I think um will give you like 18 for you to be able to use it and I think that's more of three sessions you can use that key so once you generate but you have to generate the key so once you generate the key you have to store it somewhere so but before we do that so let me just let's go to these examples here I am so in these examples you'll see a lot of you can the examples uh that you can use the Open Eye API to do but the one we're interested in today is the chat if I scroll down here I'll see the charts here so now this is a chart so but if one thing is we have a lot of so this is the basic code that you need so I'm going to explain all these things that we're going to use it in our code and I'll explain how the works the parameters the model there are there are four modules that the charges uses the DaVinci it's uses DaVinci it is query it is baggage and other so but the DaVinci is the largest and the most capable uh model so that's the one we'll be using in this tutorial will be using the DaVinci model to do the chatbot here so you can actually copy this code and edit it so here you you need the API key so but I'm going to have I have a coder now here so I'm going to show you what I have all right so this is the code there so the first line I just you have to import open AI before you can use any of these or functions and Method so once I import the open AI then uh then the next thing I have to open AI dot API key so but before that you have to generate the key so once you sign up on open AI click on the um the icon of your account you'll see view API key so once you go to VIP API Keys okay I've already generated a key as an um so that's what you're seeing um a column here for you if you just open this account and you it'd probably be an empty so it will empty and you have create new secret key here so I have a key that I created for everyone and it was last used today so and so this is the key but you don't have access to it so you have to keep it safely you see your secret API keys are it will be listed here and it's not been displayed it's only the first two and the last four characters are displayed so it is secret and are you for security reasons you don't have to share it with others how to expose it in your browser or anything so so when you generate the key then you copy it so when you copy it then that's what you paste here when you type coconut or DPI key so you create a key here now I talk about the model so model model refers to the language generation that that we're going to use and and I've said that the open AI uses our form module which is the the offer 4 module which is a DaVinci the curry the baggage and the other so we're going to be using the DaVinci because it's the largest and the most capable model to use so that's also use that so here is a prompt actually we there's another parameter when you're creating when you're trying to create it or use the opening API and um one thing you need to uh you need to provide is also the prompt and the prompt is and this is Nancy that's for our user input that's where we are trying to take you see we we're trying to take user input here but as a string so whatever questions you want to ask they um the charge of it is so it's going to be typed here and it's going to give you a feedback then we need uh this variable um the completion variable so and this variable we use it to to call on the completion method of the commissioner and create method of the open Ai and this will take several variables like I have here I have the engine the engineering meaning the model we're trying to use which is what I have here The DaVinci model that's wto3 then the next one The Prompt which will be the prompt that we specify we're taking it from our user input the the console the python console of the pycharm yeah then the next one is Max token so massive is another parameter that you actually need to specify in your uh in your code so the it is just the max token is the maximum number of tokens with uh yeah the maximum number of tokens you know we'll talk about about the model being able to tokenize almost everywhere for you to understand it better so you have to specify the maximum tokens there so it's just that the purpose of this is is just to limit the size of generated text so that we can prevent excessive or memory usage and processing time so now the one thing here we need to stop we're not running this top here then the end like the top here is the n which is one then the temperature now very important here is the temperature parameter that I want to specify so the temperature just lets you to control how confident the model should be when you're making prediction and the value ranges from zero to one so maximum is one so so you have to try and choose a temperature that is actually between zero and one because uh yeah it is a value between 0 and 1 and allow you to control Community should be so but if you lower the temperature it means the model is going to take fewer risk and completions will be more accurate and deterministic but if you increase the temperature it will result in more diverse of completion so you have to so you should choose a value between zero and one so in this case we're going to choose 0.5 so the next thing here we want to create a variable where we now want to select the choices so try to be returned to others as text so many one will ask the question then we are now printing the response or the charges is going to respond to us so this is just what we need to do that so now what I'm going to do now I'm going to run this uh code that I have here so you can run it all right so now I just have to exit let me just ask the list list 10 programming languages Let me just answer it at least 10 programming languages programming languages so all right so there we have it so we're able to communicate with a sharability so it gave us Java python see up to then you can as well as it um as well I can see uh in what year you know what's here was python created Spider-Man created so you can have to watch it so you can basically all right you see it says python was created in 1991. by who let me say by who it does actually who created python as well you know how to charge a video now all right so this is very very uh so the charge ability is just a perfect assistant for you know developers programmers so to be able to um use it not only not only that for a lot of cases like copywriters and the rights to assist you in managing so and one way I find it useful is that I can use chargeability in my programming line so I don't have to leave the python environment so maybe I'm trying to research something while writing some code I can also run it here without leaving my um ID environment so this guys so these are um you will be able to use chargeability in your python using python in your pattern of the chatbot and so don't worry what we did is just to sign up oh the first thing we did is to sign up with open AI then generate our key then be able to also install the open AI API once you do that you um attach your the API key to the open AI load API key parameter then with that we have the function and we make the channel to start production so thank you for watching this tutorial please like share and subscribe my channel thank you see you guys some other time
Info
Channel: Tech With Kazim
Views: 16,883
Rating: undefined out of 5
Keywords: chatgpt, openai, pypi, python, pycharm, api, davinci, babbage, curie, ada, model, console, terminal, key
Id: RSawDZYzWS8
Channel Id: undefined
Length: 14min 37sec (877 seconds)
Published: Thu Feb 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.