()
| 5 | const pipe = new Pipe(pipeSummary()); |
| 6 | |
| 7 | async 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 | |
| 41 | main(); |
no test coverage detected