You can stream text using the generateStream
method from foundationModels
.
If you're using streaming functionality, you'll need to provide a polyfill for ReadableStream
. You can use web-streams-polyfill
:
We also recommend installing an AsyncIterator
polyfill to enable the simple for await...of
syntax:
Make sure to include the following imports before streaming:
The generateStream
method can also accept an optional second parameter for generation options.
Before calling generateStream
, it's recommended to check if Apple Intelligence is available on the device using the isAvailable
function.