From the course: OpenAI API and MCP Development
Settings permissions with an access token
From the course: OpenAI API and MCP Development
Settings permissions with an access token
Now, after running a few tests in the Playground, we want to integrate the GitHub models into our next project that we're going to run in Codespaces. For that, you simply need to use your GitHub accounts. You can use just your GitHub credentials to access the GitHub models and also the tools. I'm going to show you how to create a personal access token, and that's going to be your key to access the language models. So no need for a password or a two-factor authentication process. you simply need your PAT, your personal access token, to integrate the GitHub models into your next project. And so for the next example, you simply need to connect to your personal GitHub account. All right, so I'm not going to show you the steps to authenticate. It is so easy that you simply need to connect to your account. That's the first step. And then from here, from your avatar, you can click, then select from the list settings, all right, and then go all the way to the bottom to the left, and go to developer settings, all the way to the bottom. And here you're going to find your list of personal access tokens, so I'm going to select fine-grained tokens, so you can see that I have a few available, and mine is expiring next year, January 15th, so at the time of recording. So that should last about 30 days, and you can always extend the expiry date whenever you can. All right, so mine is already created. Let's go back to the repositories. And this time, I'm going to take you from one repository, I'm going to take you to Codespace. And what you can do, because now you are using your personal accounts, instead of using the organization account where you can download and access the exercise files for this course. So that is a different process. I'm going to invite you to create a local repository and then connect this local repository to a remote repository. So this is what I've done here. Basically, so what you do whenever you want to create a new repository, simple. This as well should be part of the prerequisite but just go within it. You create a new one and then you just need to follow the steps to then connect to a remote. So whenever you create a new repository you're going to have all the instructions. All right so when this part is done you have your repository up and running. You can go to code and then create a new code space. So I have already one created so I'm going to take you there. So to create a new one you simply need to click here to create a new code space. That's going to be set up automatically instantly. Let's go to this one and from here we're going to be able to access the starter code for the next demonstration. Here it goes. So we We have a few starter code, which is already set up. And we want to complete this one to actually use the GitHub models. We're going to see how to interface and integrate the GitHub model. So let's go back to the documentation for that. And for that, we simply need to go to the playground. So back to the playground, so from the GitHub Marketplace and Models. And you can go here, select Code. And what is great is that you can actually switch by selecting from this drop-down list and it's going to be updated here so you don't need to actually rewrite the code so when you switch to access the code it's going to give you the code that you need to use. So I want to use actually the OpenAI SDK so from this list on the right you can just change here all right excellent so I'm gonna copy and use something similar let's go back to the code spaces, because I'm going to show you what we have for now. Let me just close this part to have a better visibility. So for now, so what we have is a system message, and below you can see that we are still using an open AI endpoint. So let's update this. Okay, so let's run some tests. So before running any tests, before writing any code, let's just make sure that we go through the steps of installation and setup. So this is similar to every other project that we have done so far, so you just need to create and activate a virtual environment, install the packages, and then you're good to go. So let's start the app. We know that for now we are using the regular endpoints. I think that I've got a typo somewhere which is line 43, so let's go back. I may have put it by a mistake at some points. All right, so let's save. Run again. And my mistake looks like I don't have OpenAI. It's missing the API key. I haven't set this one up. And that's OK, because we don't want to use it. That's OK. No problem. What we're going to do is to update this code and allow to integrate the GitHub models this time, because we know that we have the correct credentials to access the GitHub models. So let's go back to this. We're going to add this model endpoint in those two lines, line 5 and 6. I'm going to add it to the top. All right, and to define the client, it's going to be this way, right below line 8 to 11. All right, so to use the proper endpoint, but also URL with the token, which is defined up here. And actually, for the token, so let me check. So we have the client. OK, so that's going to be this client. So just remove the unnecessary line. That's going to be this one. And for the endpoint, it is defined here. Let's go back. I am missing the token. Let's go back. And I think, yeah, I have the OS, the right library. That's correct. And next, let's review the code. So next, we want to see how to actually generate a response. that's going to be by using this line so the rest which will be from line 13 all the way down to 29 so let's copy and go to where we need to update the code which will be in this location so right inside the try block we're just going to make sure that we indent properly like this and for the prints instead of using the one provided by the demonstration so from github we're going to use this one and replace here with this. Okay, so let's try that. And I think that this time, line 65, it should be indented compared to accept in the case of any error, so that's going to raise an error here. So we just had a syntax error. All right, so now we can go ahead, so we can start the app, and we're going to ask a question to the AI. So I'm going to ask a simple math question like, what is 2 and 2? Classic. My mistake. So line 57, it actually responded to this hard-coded question, line 57. So I'm going to replace to user input to make sure that I can actually interact with the AI. So let's save and start again. All right. So I'm going to ask again the same math question. So what is 2 and 2? And this time, I'm going to get 2 and 2 equals 4. So we know that this is working properly. So no problem with authentication. We used our own credentials after connecting to our GitHub account and after creating our own personal access token. So as a reminder, you're going to have access to this code space. But what you can do is using the physical exercise file that you can download from the course page to access the same code.