GO-V.ORG
As seen in

Summarizer: summarizeStreaming() method

Summarizer API

Summarizer API

The **`summarizeStreaming()`** method of the Summarizer interface generates a new summary as a ReadableStream.

## Syntax

```js-nolint
summarizeStreaming(input)
summarizeStreaming(input, options)
```

### Parameters

- `input`
- : A string representing the text to be summarized.
- `options`
- : An object specifying configuration options for the `summarizeStreaming()` operation. Possible values include:
- `context`
- : A string describing the context the input text is being used in, which helps the `Summarizer` generate a more suitable summary.
- `signal`
- : An AbortSignal object instance, which allows the `summarizeStreaming()` operation to be aborted via the associated AbortController.

### Return value

A ReadableStream containing the generated summary.

### Exceptions

- `AbortError` DOMException
- : Thrown if the `Summarizer` was previously destroyed (had Summarizer.destroy() called on it, or was aborted via its abort [`signal`](/docs/Web/API/Summarizer/create_static#signal) after creation).
- `InvalidStateError` DOMException
- : Thrown if the current Document is not active.
- `NotAllowedError` DOMException
- : Thrown if usage of the Summarizer API is blocked by a summarizer Permissions-Policy.
- `NotReadableError` DOMException
- : Thrown if the output summary was filtered by the user agent, for example because it was detected to be harmful, inaccurate, or nonsensical.
- `NotSupportedError` DOMException
- : Thrown if the provided `context` is not in language the `Summarizer` supports.
- QuotaExceededError
- : Thrown if the summarize operation exceeds the available inputQuota.
- `UnknownError` DOMException
- : Thrown if the `summarizeStreaming()` call failed for any other reason, or a reason the user agent did not wish to disclose.

## Examples

### Basic `summarizeStreaming()` usage

```js
const summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tldr",
length: "short",
});

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

- [Using the Summarizer API](/docs/Web/API/Summarizer_API/Using)
- [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev

source: MDN Web Docs mirror · page

Cite this

"Summarizer: summarizeStreaming() method". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/Summarizer/summarizeStreaming

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·