Skip to content

Commit 872f74c

Browse files
RobertCraigiestainless-app[bot]
authored andcommitted
chore(examples): add a small delay to tool-calls example streaming
1 parent bf72a08 commit 872f74c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

examples/tool-calls-stream.ts

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import {
2727
ChatCompletionMessageParam,
2828
} from 'openai/resources/chat';
2929

30+
// Used so that the each chunk coming in is noticable
31+
const CHUNK_DELAY_MS = 100;
32+
3033
// gets API Key from environment variable OPENAI_API_KEY
3134
const openai = new OpenAI();
3235

@@ -126,6 +129,9 @@ async function main() {
126129
for await (const chunk of stream) {
127130
message = messageReducer(message, chunk);
128131
writeLine(message);
132+
133+
// Add a small delay so that the chunks coming in are noticablej
134+
await new Promise((resolve) => setTimeout(resolve, CHUNK_DELAY_MS));
129135
}
130136
console.log();
131137
messages.push(message);

0 commit comments

Comments
 (0)