transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

Streaming support?

Open gduteaud opened this issue 1 year ago • 3 comments

Feature request

Add support for streaming generated outputs. This appears to be supported in the transformers library: https://huggingface.co/docs/transformers/v4.38.2/en/generation_strategies#streaming

Motivation

Because outputs take a certain time to generate, it is desirable from a user experience standpoint to be able to display outputs "live" as they are being generated, as opposed to waiting until generation is completed before displaying the output.

Your contribution

I really wish I could but unfortunately this is well beyond my ability to implement.

gduteaud avatar Mar 11 '24 23:03 gduteaud

You can use the callback_function generation parameter. For example:

https://github.com/xenova/transformers.js/blob/314b7f0dc4291e8a38a516073b710d7c6a29aefb/examples/demo-site/src/worker.js#L161-L175

xenova avatar Mar 11 '24 23:03 xenova

🤯 oh wow that's amazing, thank you!!

gduteaud avatar Mar 11 '24 23:03 gduteaud

In typescript, the options give an error if you have callback_function in options.

sroussey avatar Mar 14 '24 02:03 sroussey