Summarizer: create() static method
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
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
options
Optional-
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 (as specified in RFC 5646). Defaults to
["en"]
. expectedContextLanguages
-
An array of strings specifying the expected languages of any provided context strings (either the
sharedContext
passed to theSummarizer
, or acontext
specified during asummarize()
orsummarizeStreaming()
call), which should be valid BCP 47 language tags. Defaults to["en"]
. format
-
An enumerated value specifying the text
format
you want summaries returned in. Defaults tomarkdown
. length
-
An enumerated value specifying the relative
length
for the generated summaries. Defaults toshort
. monitor
-
A callback function with a
CreateMonitor
argument that enables monitoring download progress of the AI model. 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
sharedContext
string describing the context the pieces of text to summarize are being used in, which helps theSummarizer
generate more suitable summaries. signal
-
An
AbortSignal
object instance, which allows thecreate()
operation to be aborted via the associatedAbortController
. type
-
An enumerated value specifying the
type
of summary you want thisSummarizer
to generate. Defaults tokey-points
.
Return value
A Promise
that fulfills with a Summarizer
object instance.
Exceptions
NotAllowedError
DOMException
-
Thrown if usage of the Summarizer API is blocked by a
summarizer
Permissions-Policy
. NotSupportedError
DOMException
-
Thrown if any of the language tags specified in
expectedContextLanguages
,expectedInputLanguages
, oroutputLanguage
are invalid, or not supported. OperationError
DOMException
-
General-purpose exception thrown if
Summarizer
creation failed for any other reason.
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: "tl;dr",
length: "short",
format: "markdown",
expectedInputLanguages: ["en-US"],
outputLanguage: "en-US",
});
Specifications
Specification |
---|
Writing Assistance APIs # dom-summarizer-create |
Browser compatibility
See also
- Using the Summarizer API
- Web AI demos on chrome.dev