useSummarizer

Provides low-level access to the browser's built-in AI Summarizer API.

Caution

This hook relies on the experimental Window AI (Summarizer) API.

Important

Always call the destroy() method when the component unmounts or the summarizer is no longer needed to free up browser-side AI model resources and memory.

Tip

Use checkAvailability() before calling create() to handle cases where the model needs to be downloaded before use.

Installation

bash

Description

This hook interacts with local AI models provided by modern browsers (like Chrome's Gemini Nano integration). It allows checking if a summarization model is available, downloading it if necessary, and performing efficient, privacy-focused text summarization without sending data to a cloud server.

Return values

NameTypeDescription
cancel() => voidAborts any ongoing summarization or creation task.
checkAvailability(opts={}) => Promise<SummarizerAvailability>Checks if the AI model is 'available', 'unavailable', or 'downloadable'.
create(opts={}) => Promise<void>Instantiates the Summarizer model with specific options (type, length, format).
destroy() => voidCleans up the model instance and releases browser resources.
isAbortError(error: unknown) => booleanChecks if the provided error is an AbortError.
isSupportedbooleantrue if the browser supports the window.Summarizer API.
summarize(text: string) => Promise<string>Asynchronously processes the input text and returns a summary.

Demo

This component is loading.

Source code

tsx