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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Generating static objects3m 59s
-
(Locked)
Returning objects on the client3m 10s
-
(Locked)
Streaming generated objects3m 14s
-
(Locked)
Handling object streams3m 1s
-
(Locked)
Streaming components with server actions2m 11s
-
(Locked)
Rendering streamed components3m 40s
-
(Locked)
Solution: Creating a streaming object generator4m 48s
-
(Locked)
-
-