nano-ai-pdf
Version:
This package helps you summarize pdfs using Gemini nano on edge or on browser, making it compliant safe, faster and free
69 lines (68 loc) • 2.74 kB
TypeScript
import { PdfSummarizerOptions, PdfSummarizerResult, PdfSummarizerStreamResult } from "./types";
/**
* Summarizes a PDF file using Chrome's built-in AI Summarizer API
*
* This function extracts text from the provided PDF file and generates an AI summary
* using Chrome's on-device Summarizer model. It requires Chrome 138+ with experimental
* flags enabled and user activation (must be called from a user gesture).
*
* @param file - The PDF file to summarize
* @param options - Optional configuration for the summarization process
* @returns Promise resolving to the summarization result
*
* @throws PdfSummarizerError with specific error codes:
* - NO_FILE: No file provided
* - INVALID_FILE_TYPE: File is not a PDF
* - FILE_TOO_LARGE: File exceeds maximum size limit
* - EMPTY_FILE: PDF file is empty
* - EXTRACTION_FAILED: Failed to extract text from PDF
* - INSUFFICIENT_TEXT: PDF doesn't contain enough text
* - API_NOT_SUPPORTED: Chrome Summarizer API not available
* - USER_ACTIVATION_REQUIRED: Function not called from user gesture
* - MODEL_UNAVAILABLE: AI model not available on device
* - SUMMARIZER_CREATION_FAILED: Failed to create summarizer instance
* - SUMMARIZATION_FAILED: Failed to generate summary
*
* @example
* ```
* import { summarizePdf } from 'nano-ai-pdf';
*
* // Basic usage
* const result = await summarizePdf(pdfFile);
* console.log(result.summary);
*
* // With custom options
* const result = await summarizePdf(pdfFile, {
* type: 'tldr',
* format: 'plain-text',
* length: 'short',
* context: 'This is a technical document'
* });
* ```
*/
export declare function summarizePdf(file: File, options?: Partial<PdfSummarizerOptions>): Promise<PdfSummarizerResult>;
/**
* Summarizes a PDF file with streaming output using Chrome's built-in AI
*
* Similar to summarizePdf but returns an async iterable for real-time summary generation.
* Useful for showing progress to users as the summary is being generated.
*
* @param file - The PDF file to summarize
* @param options - Optional configuration for the summarization process
* @returns Promise resolving to streaming summarization result
*
* @example
* ```
* import { summarizePdfStreaming } from 'nano-ai-pdf';
*
* const result = await summarizePdfStreaming(pdfFile);
*
* for await (const chunk of result.summaryStream) {
* console.log('Summary chunk:', chunk);
* }
* ```
*/
export declare function summarizePdfStreaming(file: File, options?: Partial<PdfSummarizerOptions>): Promise<PdfSummarizerStreamResult>;
export * from "./types";
export { checkModelAvailability, isSummarizerSupported, getDownloadProgress, onDownloadProgressUpdate, } from "./chrome-summarizer";
export default summarizePdf;