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

Summarizer

· 52CE 我爱测

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.

Summarizer API

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

  • Summarizer.expectedContextLanguages
    • : The languages the context strings should be written in.
  • Summarizer.expectedInputLanguages
    • : The languages the Summarizer should support.
  • Summarizer.format
    • : The text format summaries will be returned in.
  • Summarizer.inputQuota
    • : The input quota available to the browser for generating summaries.
  • Summarizer.length
    • : The relative length of the generated summaries.
  • Summarizer.outputLanguage
    • : The language the summary should be generated in.
  • Summarizer.sharedContext
    • : A text string describing the context the pieces of text to summarize are being used in, which helps the Summarizer generate more suitable summaries.
  • Summarizer.type
    • : The type of summary that will be generated by the Summarizer.

Static methods

  • Summarizer.availability_static
    • : Returns an enumerated value that indicates whether the browser AI model supports a given Summarizer configuration.
  • Summarizer.create_static
    • : Creates a new Summarizer instance from which to generate summaries.

Instance methods

  • Summarizer.destroy
    • : Releases the resources assigned to the Summarizer instance it is called on and stops any further activity on it.
  • Summarizer.measureInputUsage
    • : Reports how much input quota would be used by a summarize operation for a given text input.
  • Summarizer.summarize
    • : Generates a new summary string.
  • Summarizer.summarizeStreaming
    • : Generates a new summary as a ReadableStream.

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

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

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

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