MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / main

Function main

examples/nodejs/examples/pipe.run.stream.loop.ts:7–28  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5const pipe = new Pipe(pipeSummary());
6
7async function main() {
8 // Get readable stream
9 const {stream, threadId, rawResponse} = await pipe.run({
10 messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
11 stream: true,
12 rawResponse: true,
13 });
14
15 // Convert the stream to a stream runner.
16 const runner = getRunner(stream);
17
18 // Method 2: Using `for await of` loop
19 // This will not allow callbacks lkke `connect`, `end`, `error`
20 for await (const chunk of runner) {
21 // const textPart = chunk.choices[0]?.delta?.content || '';
22 // Or use the utility function
23 const textPart = getTextContent(chunk);
24
25 // Print to the console without new line
26 process.stdout.write(textPart);
27 }
28}
29
30main();

Callers 1

Calls 3

getRunnerFunction · 0.90
getTextContentFunction · 0.90
runMethod · 0.80

Tested by

no test coverage detected