web api static method
Summarizer: create() static method
Limited availabilitySecure context
The create() static method of the Summarizer interface creates a new Summarizer instance from which to generate summaries.
[!NOTE] The
create()method requires transient activation, that is, it must be invoked in response to a user action such as a mouse click or button press.
Syntax
Summarizer.create()
Summarizer.create(options)
Parameters
optionsOptional- : An object specifying configuration options for the
Summarizer. Possible values include:expectedInputLanguages- : An array of strings specifying the expected languages of the input text, which should be valid BCP 47 language tags. Defaults to
["en"].
- : An array of strings specifying the expected languages of the input text, which should be valid BCP 47 language tags. Defaults to
expectedContextLanguages- : An array of strings specifying the expected languages of any provided context strings (either the
sharedContextpassed to theSummarizer, or acontextspecified during asummarize()orsummarizeStreaming()call), which should be valid BCP 47 language tags. Defaults to["en"].
- : An array of strings specifying the expected languages of any provided context strings (either the
format- : An enumerated value specifying the text
formatyou want summaries returned in. Defaults tomarkdown.
- : An enumerated value specifying the text
length- : An enumerated value specifying the relative
lengthfor the generated summaries. Defaults toshort.
- : An enumerated value specifying the relative
monitor- : A callback function with a
CreateMonitorargument that enables monitoring download progress of the AI model.
- : A callback function with a
outputLanguage- : A string specifying the expected language of summaries generated by the
Summarizer, which should be a valid BCP 47 language tag. Defaults toen.
- : A string specifying the expected language of summaries generated by the
sharedContext- : A
sharedContextstring describing the context the pieces of text to summarize are being used in, which helps theSummarizergenerate more suitable summaries.
- : A
signal- : An
AbortSignalobject instance, which allows acreate()operation to be aborted via the associatedAbortController. The exact effect is dependent on whenabort()is called:- If
abort()is called before thecreate()promise resolves, thecreate()operation is cancelled. - If
abort()is called after thecreate()promise fulfills, it has the same effect as callingdestroy(): The resources assigned to the resultingSummarizerinstance are released, and any ongoing and subsequentSummarizermethod calls will reject with anAbortError.
- If
- : An
type- : An enumerated value specifying the
typeof summary you want thisSummarizerto generate. Defaults tokey-points.
- : An enumerated value specifying the
- : An object specifying configuration options for the
Return value
A Promise that fulfills with a Summarizer object instance.
Exceptions
NotAllowedErrorDOMException- : Thrown if usage of the Summarizer API is blocked by a
summarizerPermissions-Policy.
- : Thrown if usage of the Summarizer API is blocked by a
NotSupportedErrorDOMException- : Thrown if any of the language tags specified in
expectedContextLanguages,expectedInputLanguages, oroutputLanguageare invalid, or not supported.
- : Thrown if any of the language tags specified in
OperationErrorDOMException- : General-purpose exception thrown if
Summarizercreation failed for any other reason.
- : General-purpose exception thrown if
Examples
Basic Summarizer creation
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",
});
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