The createChatCompletion Endpoint

Tom Chant
InstructorTom Chant
Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated a year ago

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.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today