Skip to content

Commit

Permalink
chore(examples): add a small delay to tool-calls example streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored and stainless-app[bot] committed Sep 13, 2024
1 parent bf72a08 commit 872f74c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/tool-calls-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import {
ChatCompletionMessageParam,
} from 'openai/resources/chat';

// Used so that the each chunk coming in is noticable
const CHUNK_DELAY_MS = 100;

// gets API Key from environment variable OPENAI_API_KEY
const openai = new OpenAI();

Expand Down Expand Up @@ -126,6 +129,9 @@ async function main() {
for await (const chunk of stream) {
message = messageReducer(message, chunk);
writeLine(message);

// Add a small delay so that the chunks coming in are noticablej
await new Promise((resolve) => setTimeout(resolve, CHUNK_DELAY_MS));
}
console.log();
messages.push(message);
Expand Down

0 comments on commit 872f74c

Please sign in to comment.