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 Summarizer interface of the Summarizer API contains all the functionality for this API, including checking AI model availability, creating a new Summarizer instance, using it to generate a new summary, and more.
expectedContextLanguages Read only The languages the context strings should be written in.
expectedInputLanguages Read only The languages the Summarizer should support.
format Read only The text format summaries will be returned in.
inputQuota Read only The input quota available to the browser for generating summaries.
length Read only The relative length of the generated summaries.
outputLanguage Read only The language the summary should be generated in.
A text string describing the context the pieces of text to summarize are being used in, which helps the Summarizer generate more suitable summaries.
type Read only The type of summary that will generated by the Summarizer.
availability() Returns an enumerated value that indicates whether the browser AI model supports a given Summarizer configuration.
create() Creates a new Summarizer instance from which to generate summaries.
destroy() Releases the resources assigned to the Summarizer instance it is called on and stops any further activity on it.
measureInputUsage() Reports how much input quota would be used by a summarize operation for a given text input.
summarize() Generates a new summary string.
summarizeStreaming() Generates a new summary as a ReadableStream.
See Using the Summarizer API for a complete example.
Summarizer instanceconst summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tldr",
length: "short",
format: "markdown",
expectedInputLanguages: ["en-US"],
outputLanguage: "en-US",
});const summary = await summarizer.summarize(myTextString);
console.log(summary);const stream = summarizer.summarizeStreaming(myTextString);
let summary = "";
for await (const chunk of stream) {
summary += chunk;
}
console.log("Stream complete");
summaryOutput.textContent = summary;