 Hello everybody and welcome back to another video. Today I'm going to show you how you can use ChatGPT and Jupyter Notebooks. Now I absolutely love using ChatGPT when I'm coding. I usually just open up the open AI website, type in my code into ChatGPT, and then I copy and paste it back. But when I was using Jupyter Notebooks, I was hoping I could use ChatGPT in Jupyter Notebooks and just kind of save time by going back and forth and back and forth. And I think I figured out how to do that. Now full disclosure, there's not a tutorial on how to do this. I'm not starting from scratch and building it all out. I'm just going to kind of show you what I've done and how to do it. But I do it in two different ways. The first way is using ChatGPT's API. So I just use my API key, use it within the cells in Jupyter Notebooks. And if I'm being honest, this is not the best way to do that. I'll show that to you in just a little bit. The second way you do it and the way that I recommend it is this extension that I found that integrates into your Jupyter Notebooks. And it is phenomenal. I just started using it about two weeks ago when I was like, whoa, this is really, really helpful. It's basically like having ChatGPT with you there when you're coding in Jupyter Notebooks. It's phenomenal. And I think it's really, really helpful. I just wanted to show it to you. So let's jump onto my screen. We'll take a look and we'll see how we can put ChatGPT into your Jupyter Notebooks. All right. So the first way that I want to show you how you can use ChatGPT in Jupyter Notebooks is by using the API key. Now you are not going to use this API key because I will go and delete it. But you can try it if you want to. I'll have that on my GitHub where I post this. So you can just copy this and try that yourself. But to actually install this, you need your own API key. So you just have to go to the OpenAI account API keys, create your own API. Of course, this does cost money, but I've used it quite a few times and it's costing me like six cents. So it's crazy cheap. But you go and you get your API key, you copy that. And then you go over here and we input it as our API key. We have this function that we created and then we prompt it. So we say prompt, what are the benefits of using renewable energy and it gives us this output. Now, here's what I found about the API really quickly is that when you do it like this and you're using the API key like this in your Jupyter Notebook, it's extremely limited. It's actually not super even helpful. I would just go into Bing or ChatGPT and use it there. So if I'm being honest, this isn't the best way to do it. I would probably, if I was trying to really make the most out of this, I would try to create some type of user interface or button or something that I can use on the side over here that would integrate maybe like a widget or something. This just isn't great. And this is what most people are going to do. This is what I tried to do when I was first doing it. And if you're having trouble, you may need to do PIP install OpenAI in your Anaconda prompt if you're using it through Anaconda. That's where I'm using it through. So just PIP install, it installs it. And then of course you can use this exact code right here. Again, don't really recommend it. It's honestly not that great, but this is how you do it. Now, when I was going through all the research to find this, I found this right here. This is the ChatGPT Jupyter AI Assistant. It is super great. And I found this and I was like, Hey, I need to make a video on this, not for anything more than to just show it to you. In case you use Jupyter Notebooks in your work, this is a fantastic integration. And they even have all of the code for it in their GitHub. So you can go and you can literally clone this and create your own if you want to with any extra code you would like to do. But he walks through how he created it, what it does, everything in here. Now, really quickly, I'm just going to give you a quick demonstration of how it works. But when you install it, you come right here. I've already installed it, but you just select install or download, then you refresh. Your Jupyter Notebook. And then you get all these buttons up here. Buttons like format, explain, debug, complete, review, question. And then there is a voice question. Now, all of these other functions are completely free. But if you go to the very bottom right here, it says that the voice command, you can ask it questions. This part does cost money. Actually, he talks about how much it costs right down, right up here, actually. It's the voice command. So it uses the whisper API and charges 0.006 per minute. So if you do use that, that costs money. But everything else is completely free, which is just, it's fantastic. So if we go back here, let's go down. And let's say I have this error right here. For example, I can come in here and I can click debug. And if I click debug, right at the bottom, it starts prompting or creating this output for us. It's only at the very bottom. But it even says, look, there's an issue with your code. It looks like you needed a semicolon or a colon. So it corrects the code. And you can just copy that, which is fantastic. Or you can come right over here and click copy. And you can then paste it into here. And it'll work better. And actually, that's an issue because I need to get rid of this. There we go. So that's how they get around that. Now, it's free because they're using the ChatGBT 3.5. They're not using the ChatGBT 4, which would cost you money. And I believe you can actually upgrade that as well. When you're actually adding this, you do need an API key in order to use this. You just have to input it in case you do use the whisper API, then it charges you. But I've been using this quite a bit, just testing it out, running a bunch of tests and different stuff. And it's been working perfectly. Let's go back up really quickly. And let me get rid of this. I'm zoomed in. Let me get rid of this. And let's say I want to do something like format or let me do the complete. So I'll just do this right here. And let's say I wanted to do num times. I'm just going to get rid of this. And then we'll do complete. So now it's going to say num 2. And it's even going to give us different stuff. It's going to do a list comprehension. So we didn't say do num to the power of 2, but I think it saw our last query right here. And it's going to work perfect. So we're just going to copy this. And we're going to paste it down here. And if we run this, it gives us an output. So it changed this, which basically is nothing. This is hot garbage. And it changed it into a nice little query for whatever you're using it for. As you get more complex, of course, it's going to be more tough and it's going to have different options and it may get things wrong. But this is exactly working off what you would have gotten if you just plug this into the chat GPT window or their website. So I thought this was just really, really cool. And if I click on this, I can even go over here. I can have it explain it to me. And now it's going to explain this code to me all within my browser, which again, I just really like. And it keeps it super simple. So they're using it using list comprehension, squared list and element, blah, blah, blah, blah. So it just explains the code to you. Now this isn't a full tutorial on how to use this. So I'm not going to show you every single thing. I just wanted to show you how you can use the API key. How it's not super useful. And this extension that I found that I've been using for a little while and it's been working awesome. So wanted to show this to you. Thought it would be helpful. Thought it would be useful. If you were interested in this, I'm going to leave links to basically all of these in the description to where you can access your API key, to the GitHub with this code that I don't really recommend to this extension and this GitHub repo as well. So I hope that this was helpful. If you use Jupyter Notebooks, I highly recommend downloading this extension. It's just super cool. If you like this video, be sure to like and subscribe below. And I will see you in the next video.