TextSummarizer class

Performs text summarization on input text.

Signature:

export declare class TextSummarizer extends TaskRunner 

Extends: TaskRunner

Methods

Method Modifiers Description
close() Cleans up the resources held by the TextSummarizer.
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 from the provided options.
setOptions(options) Sets new options for the text summarizer.
summarize(text) Summarizes the provided text synchronously.
summarizeStreaming(text, progressListener) Summarizes the provided text with streaming token callbacks and resolves with the final summary.

TextSummarizer.close()

Cleans up the resources held by the TextSummarizer.

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?: TextSummarizerMode): 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 A binary representation of the model or a stream reader.
maxNumTokens number Optional maximum number of tokens for input and output combined.
mode TextSummarizerMode Optional summarization style mode ('TLDR' or 'KEYPOINTS').

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: TrustedResourceUrl | string, maxNumTokens?: number, mode?: TextSummarizerMode): Promise<TextSummarizer>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetPath TrustedResourceUrl | string The path to the model asset.
maxNumTokens number Optional maximum number of tokens for input and output combined.
mode TextSummarizerMode Optional summarization style mode ('TLDR' or 'KEYPOINTS').

Returns:

Promise<TextSummarizer>

TextSummarizer.createFromOptions()

Initializes the Wasm runtime and creates a new text summarizer from 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 the text summarizer.

Returns:

Promise<TextSummarizer>

TextSummarizer.setOptions()

Sets new options for the text summarizer.

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 provided text synchronously.

Signature:

summarize(text: string): TextSummarizerResult;

Parameters

Parameter Type Description
text string The input text to summarize.

Returns:

TextSummarizerResult

TextSummarizer.summarizeStreaming()

Summarizes the provided text with streaming token callbacks and resolves with the final summary.

Signature:

summarizeStreaming(text: string, progressListener?: (partialSummary: string, done: boolean) => void): Promise<TextSummarizerResult>;

Parameters

Parameter Type Description
text string The input text to summarize.
progressListener (partialSummary: string, done: boolean) => void Optional callback invoked with incremental generated summary chunks.

Returns:

Promise<TextSummarizerResult>