From a3fc65928af7085d1d8d785ad4765fedc3955641 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Fri, 13 Sep 2024 18:45:42 +0100 Subject: [PATCH] chore(examples): add a small delay to tool-calls example streaming --- examples/tool-calls-stream.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/tool-calls-stream.ts b/examples/tool-calls-stream.ts index 687ea86fd..93f16a245 100755 --- a/examples/tool-calls-stream.ts +++ b/examples/tool-calls-stream.ts @@ -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(); @@ -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);