Summarizer: summarizeStreaming() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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.
Syntax
summarizeStreaming(input)
summarizeStreaming(input, options)
Parameters
input-
A string representing the text to be summarized.
optionsOptional-
An object specifying configuration options for the
summarizeStreaming()operation. Possible values include:context-
A string describing the context the input text is being used in, which helps the
Summarizergenerate a more suitable summary. signal-
An
AbortSignalobject instance, which allows thesummarizeStreaming()operation to be aborted via the associatedAbortController.
Return value
A ReadableStream containing the generated summary.
Exceptions
InvalidStateErrorDOMException-
Thrown if the current
Documentis not active. NotAllowedErrorDOMException-
Thrown if usage of the Summarizer API is blocked by a
summarizerPermissions-Policy. NotReadableErrorDOMException-
Thrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
NotSupportedErrorDOMException-
Thrown if the provided
contextis not in language theSummarizersupports. QuotaExceededError-
Thrown if the summarize operation exceeds the available
inputQuota. UnknownErrorDOMException-
Thrown if the
summarizeStreaming()call failed for any other reason, or a reason the user agent did not wish to disclose.
Examples
>Basic summarizeStreaming() usage
const 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;
Specifications
| Specification |
|---|
| Writing Assistance APIs> # dom-summarizer-summarizestreaming> |
Browser compatibility
Loading…
See also
- Using the Summarizer API
- Web AI demos on chrome.dev