The result of a generation can also be used as a stream


function generate(
    task: string,
    options: GenerationOption,
): Generation; // Generation implements the Readable interface from

The stream should send the result token by token instead of waiting for the whole answer.

NOTE: Cohere doesn't support streams yet and will return the entire answer in one chunk

πŸ’‘ Example

The result can be piped to a writable stream with the pipe method or individuals chunks can be retrieved using the .on method as seen in the stream api

const resultStream = polyfire.generate("Who was the first man to walk on the moon?", { stream: true });

resultStream.on("data", console.log); // In this should start printing the result word by word