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.

Streaming generated objects

Streaming generated objects - React.js Tutorial

From the course: AI for React Developers

Streaming generated objects

- [Instructor] Right now, we're returning our structured object, but we might want to make a little change to this so that we can stream those object results back as they're ready. So what we want to do is we will replace this with streamObject from ai. We'll continue to use our OpenAI value, and then we'll also import createStreamableValue from ai/rsc. Great. So then I can use Generate, which we will still grab the input, we'll still use our use server directive, and then everything else that's here is going to be slightly adjusted. So we need to create a variable for a stream, which is the createStreamableValue. Then we're going to create a function, an asynchronous function that's going to be immediately invoked. So we'll use this little pattern here that we saw before. Now within this, we're going to grab everything that is part of this function. We'll place that right in here. And let me zoom out a little…

Contents