In this lesson, we learn how to send user instructions and input to an API in a chat application. We start by setting up an event listener for a submit action and call the fetchReply
function. This function, marked as async
, awaits the API call response. Instead of the previous endpoints, we now explore the createChatCompletion
endpoint in the API documentation.
We focus on a code example provided to understand the usage of openAI.createChatCompletion
. Returning to the code, we add this endpoint, passing an object similar to previous endpoints. This lesson helps us understand the process of integrating API calls in a chat application and exploring different API endpoints.
[00:00] Okay, so we've got our conversation so far and it consists of two objects, the instructions object and the user input object. So let's work on sending them off to the API. So back in index.js then, when the event listener detects a submit, let's call a function called fetchReply.
[00:20] And I'll come down here and set the function up. And because this function will be calling the API, this will be an async function. Next, let's store the response to a const and await the API call. Now, so far at this point, we've been using the createCompletion and createImage endpoints. But now we're going to use something different.
[00:44] Let's head over to the API docs and see what we can find. And this slide is, of course, a link to those docs. What I'm looking at here is the API reference for createChatCompletion. And there's a ton of info on this page, and we will be investigating it more soon.
[01:00] But I want to focus in on the code example they give us right here, and specifically this. It says openAI.createChatCompletion. OK, let's go back to the code and we're going to add createChatCompletion right here. And just like with the other endpoints, we're going to pass it an object. So in the next scrim, let's head back to the docs
[01:22] and investigate what information this endpoint needs from us. Thanks.