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

Function main

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

Source from the content-addressed store, hash-verified

5const pipe = new Pipe(pipeSummary());
6
7async function main() {
8 const userMsg = 'Who is an AI Engineer?';
9
10 // Get readable stream
11 const {stream, threadId, rawResponse} = await pipe.run({
12 messages: [{role: 'user', content: userMsg}],
13 stream: true,
14 rawResponse: true,
15 });
16
17 // Convert the stream to a stream runner.
18 const runner = getRunner(stream);
19
20 // Method 1: Using event listeners
21 runner.on('connect', () => {
22 console.log('Stream started.\n');
23 });
24
25 runner.on('content', content => {
26 process.stdout.write(content);
27 });
28
29 runner.on('end', () => {
30 console.log('\nStream ended.');
31 });
32
33 runner.on('error', error => {
34 console.error('Error:', error);
35 });
36
37 // Method 2: Using `for await of` loop
38 // Check the `pipe.run.stream.loop.ts` example for this method
39}
40
41main();

Callers 1

pipe.run.stream.tsFile · 0.70

Calls 3

getRunnerFunction · 0.90
runMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected