web api interface
Summarizer
Limited availabilitySecure context
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.
Instance properties
expectedContextLanguagesRead only Experimental- : The languages the context strings should be written in.
expectedInputLanguagesRead only Experimental- : The languages the
Summarizershould support.
- : The languages the
formatRead only Experimental- : The text format summaries will be returned in.
inputQuotaRead only Experimental- : The input quota available to the browser for generating summaries.
lengthRead only Experimental- : The relative length of the generated summaries.
outputLanguageRead only Experimental- : The language the summary should be generated in.
sharedContextRead only Experimental- : A text string describing the context the pieces of text to summarize are being used in, which helps the
Summarizergenerate more suitable summaries.
- : A text string describing the context the pieces of text to summarize are being used in, which helps the
typeRead only Experimental- : The type of summary that will generated by the
Summarizer.
- : The type of summary that will generated by the
Static methods
availability()Experimental- : Returns an enumerated value that indicates whether the browser AI model supports a given
Summarizerconfiguration.
- : Returns an enumerated value that indicates whether the browser AI model supports a given
create()Experimental- : Creates a new
Summarizerinstance from which to generate summaries.
- : Creates a new
Instance methods
destroy()Experimental- : Releases the resources assigned to the
Summarizerinstance it is called on and stops any further activity on it.
- : Releases the resources assigned to the
measureInputUsage()Experimental- : Reports how much input quota would be used by a summarize operation for a given text input.
summarize()Experimental- : Generates a new summary string.
summarizeStreaming()Experimental- : Generates a new summary as a
ReadableStream.
- : Generates a new summary as a
Examples
See Using the Summarizer API for a complete example.
Creating a Summarizer instance
const 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",
});
Generating a summary
const summary = await summarizer.summarize(myTextString);
console.log(summary);
Generating a summary stream
const stream = summarizer.summarizeStreaming(myTextString);
let summary = "";
for await (const chunk of stream) {
summary += chunk;
}
console.log("Stream complete");
summaryOutput.textContent = summary;
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- Using the Summarizer API
- Web AI demos on chrome.dev