Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

BatchStrategy.md

85 lines1.7 KB

1---
2id: BatchStrategy
3title: BatchStrategy
4---
5​
6Defined in: [packages/ai/src/activities/chat/stream/strategies.ts:34](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/stream/strategies.ts#L34)
7​
8Batch Strategy - emit every N chunks
9Useful for reducing UI update frequency
10​
11## Implements
12​
13- [`ChunkStrategy`](../interfaces/ChunkStrategy.md)
14​
15## Constructors
16​
17### Constructor
18​
19```ts
20new BatchStrategy(batchSize?): BatchStrategy;
21```
22​
23Defined in: [packages/ai/src/activities/chat/stream/strategies.ts:37](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/stream/strategies.ts#L37)
24​
25#### Parameters
26​
27##### batchSize?
28​
29`number` = `5`
30​
31#### Returns
32​
33`BatchStrategy`
34​
35## Methods
36​
37### reset()
38​
39```ts
40reset(): void;
41```
42​
43Defined in: [packages/ai/src/activities/chat/stream/strategies.ts:48](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/stream/strategies.ts#L48)
44​
45Optional: Reset strategy state (called when streaming starts)
46​
47#### Returns
48​
49`void`
50​
51#### Implementation of
52​
53[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`reset`](../interfaces/ChunkStrategy.md#reset)
54​
55***
56​
57### shouldEmit()
58​
59```ts
60shouldEmit(_chunk, _accumulated): boolean;
61```
62​
63Defined in: [packages/ai/src/activities/chat/stream/strategies.ts:39](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/chat/stream/strategies.ts#L39)
64​
65Called for each text chunk received
66​
67#### Parameters
68​
69##### \_chunk
70​
71`string`
72​
73##### \_accumulated
74​
75`string`
76​
77#### Returns
78​
79`boolean`
80​
81true if an update should be emitted now
82​
83#### Implementation of
84​
85[`ChunkStrategy`](../interfaces/ChunkStrategy.md).[`shouldEmit`](../interfaces/ChunkStrategy.md#shouldemit)