From the course: AI for React Developers

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Using the useCompletion hook

Using the useCompletion hook - React.js Tutorial

From the course: AI for React Developers

Using the useCompletion hook

- [Instructor] Let's make a quick change to our route JS file. I want to add, instead of messages, which we'll deal with in a little bit, let's just add a prompt. Think of a prompt as being like an instruction or a question that you ask your AI. So the one I'll ask here is, what is a fun thing to do in Bend, Oregon? Now if I go to my page JS file, this is where I'm going to start to work with the data that comes back from this API request. So let's import use completion from AI slash react. Now, as soon as we see the word use, we probably can assume that this is some sort of a hook. It's a react function that's going to allow us to parse some sort of response or handle state or whatever really comes back from calling the use completion function. So what is going to come back that we're going to make use of we'll destructure completion, input, handle input change and handle submit. Let's walk through what all these…

Contents