TextSummarizer class

MediaPipe Task that performs text summarization.

Signature:

export declare class TextSummarizer extends TaskRunner 

Extends: TaskRunner

Methods

Method Modifiers Description
close() Closes the TextSummarizer and frees resources.
createFromModelBuffer(wasmFileset, modelAssetBuffer, maxNumTokens, mode) static Initializes the Wasm runtime and creates a new text summarizer based on the provided model asset buffer.
createFromModelPath(wasmFileset, modelAssetPath, maxNumTokens, mode) static Initializes the Wasm runtime and creates a new text summarizer based on the path to the model asset.
createFromOptions(wasmFileset, textSummarizerOptions) static Initializes the Wasm runtime and creates a new text summarizer based on the provided options.
setOptions(options) Sets the initial options for the text summarizer. LiteRT LM Tasks do not support updating options after initialization.
summarize(text) Summarizes the given text.
summarizeStreaming(text, progressListener) Summarizes the given text and reports the summary incrementally, as soon as each chunk is generated.Only one summarization can be in flight at a time. As the underlying Wasm engine runs single-threaded, the calling browser thread remains blocked for the duration of this inference call, and the listener is invoked synchronously. Run the task in a Web Worker to keep the UI thread responsive.

TextSummarizer.close()

Closes the TextSummarizer and frees resources.

Signature:

close(): void;

Returns:

void

TextSummarizer.createFromModelBuffer()

Initializes the Wasm runtime and creates a new text summarizer based on the provided model asset buffer.

Signature:

static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader, maxNumTokens?: number, mode?: SummarizationMode): Promise<TextSummarizer>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetBuffer Uint8Array | ReadableStreamDefaultReader An array or a stream containing a binary representation of the model.
maxNumTokens number The maximum number of tokens to generate.
mode SummarizationMode The summarization mode.

Returns:

Promise<TextSummarizer>

TextSummarizer.createFromModelPath()

Initializes the Wasm runtime and creates a new text summarizer based on the path to the model asset.

Signature:

static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string, maxNumTokens?: number, mode?: SummarizationMode): Promise<TextSummarizer>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetPath string The path to the model asset.
maxNumTokens number The maximum number of tokens to generate.
mode SummarizationMode The summarization mode.

Returns:

Promise<TextSummarizer>

TextSummarizer.createFromOptions()

Initializes the Wasm runtime and creates a new text summarizer based on the provided options.

Signature:

static createFromOptions(wasmFileset: WasmFileset, textSummarizerOptions: TextSummarizerOptions): Promise<TextSummarizer>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
textSummarizerOptions TextSummarizerOptions The options for TextSummarizer.

Returns:

Promise<TextSummarizer>

TextSummarizer.setOptions()

Sets the initial options for the text summarizer. LiteRT LM Tasks do not support updating options after initialization.

Signature:

setOptions(options: TextSummarizerOptions): Promise<void>;

Parameters

Parameter Type Description
options TextSummarizerOptions The options for the text summarizer.

Returns:

Promise<void>

TextSummarizer.summarize()

Summarizes the given text.

Signature:

summarize(text: string): TextSummarizerResult;

Parameters

Parameter Type Description
text string The input text to be summarized. The generated summary.

Returns:

TextSummarizerResult

TextSummarizer.summarizeStreaming()

Summarizes the given text and reports the summary incrementally, as soon as each chunk is generated.

Only one summarization can be in flight at a time. As the underlying Wasm engine runs single-threaded, the calling browser thread remains blocked for the duration of this inference call, and the listener is invoked synchronously. Run the task in a Web Worker to keep the UI thread responsive.

Signature:

summarizeStreaming(text: string, progressListener?: SummarizerProgressListener): Promise<TextSummarizerResult>;

Parameters

Parameter Type Description
text string The input text to be summarized.
progressListener SummarizerProgressListener An optional listener that receives each newly generated part of the summary. A promise that resolves to the complete generated summary.

Returns:

Promise<TextSummarizerResult>