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