UNPKG

@tanstack/ai

Version:

Core TanStack AI library - Open source AI SDK

101 lines (100 loc) 3.74 kB
import { SummarizeAdapter } from './adapter.js'; import { StreamChunk, SummarizationResult } from '../../types.js'; /** The adapter kind this activity handles */ export declare const kind: "summarize"; /** Extract provider options from a SummarizeAdapter via ~types */ export type SummarizeProviderOptions<TAdapter> = TAdapter extends SummarizeAdapter<any, any> ? TAdapter['~types']['providerOptions'] : object; /** * Options for the summarize activity. * The model is extracted from the adapter's model property. * * @template TAdapter - The summarize adapter type * @template TStream - Whether to stream the output */ export interface SummarizeActivityOptions<TAdapter extends SummarizeAdapter<string, object>, TStream extends boolean = false> { /** The summarize adapter to use (must be created with a model) */ adapter: TAdapter & { kind: typeof kind; }; /** The text to summarize */ text: string; /** Maximum length of the summary (in words or characters, provider-dependent) */ maxLength?: number; /** Style of summary to generate */ style?: 'bullet-points' | 'paragraph' | 'concise'; /** Topics or aspects to focus on in the summary */ focus?: Array<string>; /** Provider-specific options */ modelOptions?: SummarizeProviderOptions<TAdapter>; /** * Whether to stream the summarization result. * When true, returns an AsyncIterable<StreamChunk> for streaming output. * When false or not provided, returns a Promise<SummarizationResult>. * * @default false */ stream?: TStream; } /** * Result type for the summarize activity. * - If stream is true: AsyncIterable<StreamChunk> * - Otherwise: Promise<SummarizationResult> */ export type SummarizeActivityResult<TStream extends boolean> = TStream extends true ? AsyncIterable<StreamChunk> : Promise<SummarizationResult>; /** * Summarize activity - generates summaries from text. * * Supports both streaming and non-streaming modes. * * @example Basic summarization * ```ts * import { summarize } from '@tanstack/ai' * import { openaiSummarize } from '@tanstack/ai-openai' * * const result = await summarize({ * adapter: openaiSummarize('gpt-4o-mini'), * text: 'Long article text here...' * }) * * console.log(result.summary) * ``` * * @example Summarization with style * ```ts * const result = await summarize({ * adapter: openaiSummarize('gpt-4o-mini'), * text: 'Long article text here...', * style: 'bullet-points', * maxLength: 100 * }) * ``` * * @example Focused summarization * ```ts * const result = await summarize({ * adapter: openaiSummarize('gpt-4o-mini'), * text: 'Long technical document...', * focus: ['key findings', 'methodology'] * }) * ``` * * @example Streaming summarization * ```ts * for await (const chunk of summarize({ * adapter: openaiSummarize('gpt-4o-mini'), * text: 'Long article text here...', * stream: true * })) { * if (chunk.type === 'content') { * process.stdout.write(chunk.delta) * } * } * ``` */ export declare function summarize<TAdapter extends SummarizeAdapter<string, object>, TStream extends boolean = false>(options: SummarizeActivityOptions<TAdapter, TStream>): SummarizeActivityResult<TStream>; /** * Create typed options for the summarize() function without executing. */ export declare function createSummarizeOptions<TAdapter extends SummarizeAdapter<string, object>, TStream extends boolean = false>(options: SummarizeActivityOptions<TAdapter, TStream>): SummarizeActivityOptions<TAdapter, TStream>; export type { SummarizeAdapter, SummarizeAdapterConfig, AnySummarizeAdapter, } from './adapter.js'; export { BaseSummarizeAdapter } from './adapter.js';