Open History to see the last commit
1---
2id: summarize
3title: summarize
4---
5
6# Function: summarize()
7
8```ts
9function summarize<TAdapter, TStream>(options): SummarizeActivityResult<TStream>;
10```
11
12Defined in: [activities/summarize/index.ts:146](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/activities/summarize/index.ts#L146)
13
14Summarize activity - generates summaries from text.
15
16Supports both streaming and non-streaming modes.
17
18## Type Parameters
19
20### TAdapter
21
22`TAdapter` *extends* [`SummarizeAdapter`](../interfaces/SummarizeAdapter.md)\<`string`, `object`\>
23
24### TStream
25
26`TStream` *extends* `boolean` = `false`
27
28## Parameters
29
30### options
31
32`SummarizeActivityOptions`\<`TAdapter`, `TStream`\>
33
34## Returns
35
36`SummarizeActivityResult`\<`TStream`\>
37
38## Examples
39
40```ts
41import { summarize } from '@tanstack/ai'
42import { openaiSummarize } from '@tanstack/ai-openai'
43
44const result = await summarize({
45 adapter: openaiSummarize('gpt-4o-mini'),
46 text: 'Long article text here...'
47})
48
49console.log(result.summary)
50```
51
52```ts
53const result = await summarize({
54 adapter: openaiSummarize('gpt-4o-mini'),
55 text: 'Long article text here...',
56 style: 'bullet-points',
57 maxLength: 100
58})
59```
60
61```ts
62const result = await summarize({
63 adapter: openaiSummarize('gpt-4o-mini'),
64 text: 'Long technical document...',
65 focus: ['key findings', 'methodology']
66})
67```
68
69```ts
70for await (const chunk of summarize({
71 adapter: openaiSummarize('gpt-4o-mini'),
72 text: 'Long article text here...',
73 stream: true
74})) {
75 if (chunk.type === 'content') {
76 process.stdout.write(chunk.delta)
77 }
78}
79```