generative-ai-js icon indicating copy to clipboard operation
generative-ai-js copied to clipboard

Enhance generateContentStream with streamCallbacks support. Fixes #322 #401

Open demoncoder-crypto opened this issue 8 months ago • 1 comments

Add streamCallbacks to generateContentStream

Changes

  • Added a StreamCallbacks interface with onData and onDone callback functions
  • Updated generateContentStream to accept and process the callbacks

Example Usage

await model.generateContentStream("Tell me a joke", {}, {
  onData: (chunk) => process.stdout.write(chunk),  
  onDone: (fullText) => console.log("\nFinal output:", fullText),
});

Testing

The changes have been tested with both unit tests and manual validation.

demoncoder-crypto avatar Mar 08 '25 22:03 demoncoder-crypto