From the course: Building a Project with the ChatGPT API

Test the APIs - ChatGPT Tutorial

From the course: Building a Project with the ChatGPT API

Test the APIs

- Once you have an API key, testing APIs are easy. I will show you three different ways to test and explore APIs. Feel free to use the one that works best for you. I encourage you to play around and familiarize yourself with them before incorporating them into your application code. You can use a free tool like Curl. Curl comes pre-installed on Windows and Mac. Otherwise, you can download the package from the Curl website. I love OpenAI's API documentation because they provide the sample Curl commands for you. Let's go there and copy and paste the command for the Chat Completions API Click on Copy. We'll take the request and paste it into a terminal window. Let's navigate there now. In an upcoming video, we will explore the deeper details of the requests. Just notice the model name that we're testing here is GPT-3.5 Turbo, in the request body that we are passing in a system message, "You are a helpful assistant," and the message of, "Hello." When we run this code, what happens is very interesting. There is an authentication error that says, "You didn't provide an API key." As we learned in the last lesson, you'll need to use your backstage pass to authenticate to the API. You'll simply replace this OpenAI API key up here with your API key. Once you do that and execute the code again, the response from the model should be, "Hi, how can I assist you today?" Another way to test the API is through a free tool called Postman, which has a nice visual interface. You can find the API URL in the documentation. Let's review calling the API from Postman. I've set up a post request. I've added the full URL. I've added the API key under the authentication tab as a bearer token, and I've set up the body here just simply copying and pasting the body from the Curl request. Let's click Send. Notice the model that we are using here is GPT-3.5 Turbo, and the message or the prompt that is being sent in is a simple hello. Notice here on line 11, the response from the model is, "Hello, how can I assist you today?" You can save the request to a collection so that it's available later. The third way to test is through OpenAI's Playground, which is easy to use. In the environment, you'll see a way to access the different models, send in completion parameters like temperature, top P, frequency penalty, and more. You'll notice that you will not need to enter an API key to use the APIs from this environment. We're selecting Chat mode and we're selecting the GPT-3 0.5 Turbo model. Here, let's enter a user message and we'll simply type hello and click Submit. And the assistant responds with, "Hello, how can I assist you today?" I encourage you to explore other APIs using either Curl, Postman, or the Playground environment. Now that you understand how to test the APIs, let's get hands on with the Chat Completion API and start building our application that reviews a website and summarizes the content in a tweet-friendly format. See you in the next video.

Contents