Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The summarizeStreaming() method of the Summarizer interface generates a new summary as a ReadableStream.
summarizeStreaming(input)
summarizeStreaming(input, options)inputA string representing the text to be summarized.
options OptionalAn object specifying configuration options for the summarizeStreaming() operation. Possible values include:
contextA string describing the context the input text is being used in, which helps the Summarizer generate a more suitable summary.
signalAn AbortSignal object instance, which allows the summarizeStreaming() operation to be aborted via the associated AbortController.
A ReadableStream containing the generated summary.
AbortError DOMExceptionThrown if the Summarizer was previously destroyed (had Summarizer.destroy() called on it, or was aborted via its abort signal after creation).
InvalidStateError DOMExceptionThrown if the current Document is not active.
NotAllowedError DOMExceptionThrown if usage of the Summarizer API is blocked by a summarizer Permissions-Policy.
NotReadableError DOMExceptionThrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
NotSupportedError DOMExceptionThrown if the provided context is not in language the Summarizer supports.
QuotaExceededErrorThrown if the summarize operation exceeds the available inputQuota.
UnknownError DOMExceptionThrown if the summarizeStreaming() call failed for any other reason, or a reason the user agent did not wish to disclose.
summarizeStreaming() usageconst summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tldr",
length: "short",
});
const stream = summarizer.summarizeStreaming(myTextString);
let summary = "";
for await (const chunk of stream) {
summary += chunk;
}
console.log("Stream complete");
summaryOutput.textContent = summary;