大网数据广告活动
Web 标准与前端开发

Summarizer: create() static method

· 52CE 我爱测

The **`create()`** static method of the Summarizer interface creates a new `Summarizer` instance from which to generate summaries.

Summarizer API

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
    • : 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 tag. Defaults to ["en"].
      • expectedContextLanguages
        • : An array of strings specifying the expected languages of any provided context strings (either the sharedContext passed to the Summarizer, or a context specified during a Summarizer.summarize or Summarizer.summarizeStreaming call), which should be valid BCP 47 language tags. Defaults to ["en"].
      • format
        • : An enumerated value specifying the text Summarizer.format you want summaries returned in. Defaults to markdown.
      • length
        • : An enumerated value specifying the relative Summarizer.length for the generated summaries. Defaults to short.
      • 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 to en.
      • sharedContext
        • : A Summarizer.sharedContext string describing the context the pieces of text to summarize are being used in, which helps the Summarizer generate more suitable summaries.
      • signal
        • : An AbortSignal object instance, which allows a create() operation to be aborted via the associated AbortController. The exact effect is dependent on when AbortController.abort() is called:
          • If abort() is called before the create() promise resolves, the create() operation is canceled.
          • If abort() is called after the create() promise fulfills, it has the same effect as calling Summarizer.destroy(): The resources assigned to the resulting Summarizer instance are released, and any ongoing and subsequent Summarizer method calls will reject with an AbortError.
      • type
        • : An enumerated value specifying the Summarizer.type of summary you want this Summarizer to generate. Defaults to key-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 Permissions-Policy/summarizer Permissions-Policy.
  • NotSupportedError DOMException
    • : Thrown if any of the language tags specified in expectedContextLanguages, expectedInputLanguages, or outputLanguage 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: "tldr",
  length: "short",
  format: "markdown",
  expectedInputLanguages: ["en-US"],
  outputLanguage: "en-US",
});

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。