Open History to see the last commit
1---
2id: summarize
3title: summarize
4---
5
6```ts
7function summarize<TAdapter, TStream>(options): SummarizeActivityResult<TStream>;
8```
9
10Defined in: packages/ai/src/activities/summarize/index.ts:210
11
12Summarize activity - generates summaries from text.
13
14Supports both streaming and non-streaming modes.
15
16## Type Parameters
17
18### TAdapter
19
20`TAdapter` *extends* [`SummarizeAdapter`](../interfaces/SummarizeAdapter.md)\<`string`, `object`\>
21
22### TStream
23
24`TStream` *extends* `boolean` = `false`
25
26## Parameters
27
28### options
29
30`SummarizeActivityOptions`\<`TAdapter`, `TStream`\>
31
32## Returns
33
34`SummarizeActivityResult`\<`TStream`\>
35
36## Examples
37
38**Basic summarization**
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 threadId,
48})
49
50console.log(result.summary)
51```
52
53**Summarization with style**
54
55```ts
56const result = await summarize({
57 adapter: openaiSummarize('gpt-4o-mini'),
58 text: 'Long article text here...',
59 threadId,
60 style: 'bullet-points',
61 maxLength: 100
62})
63```
64
65**Focused summarization**
66
67```ts
68const result = await summarize({
69 adapter: openaiSummarize('gpt-4o-mini'),
70 text: 'Long technical document...',
71 threadId,
72 focus: ['key findings', 'methodology']
73})
74```
75
76**Streaming summarization**
77
78```ts
79for await (const chunk of summarize({
80 adapter: openaiSummarize('gpt-4o-mini'),
81 text: 'Long article text here...',
82 threadId,
83 stream: true
84})) {
85 if (chunk.type === 'content') {
86 process.stdout.write(chunk.delta)
87 }
88}
89```