Generate: Enable easier TextStreamer customization#22516
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
gante
left a comment
There was a problem hiding this comment.
I like the structure, but I dislike the name on_new_token. It's actually a callback on "new print-ready text". Perhaps on_finalized_text? WDYT?
@gante I am completely indifferent regarding the name. Please adjust the name as you like! |
|
Let's keep it in |
39bbf19 to
9c275b7
Compare
sgugger
left a comment
There was a problem hiding this comment.
LGTM, thanks for your contribution!
What does this PR do?
Minimally adapts recently integrated (#22449) by adding a more obvious API hook for streaming tokens yet retains all the current semantics.
I am excited to use TextStreamer but I found the hook-in API not as intuitive as it could be if one needs to customize token printing. For example, I need to use specific colouring to print arriving tokens, yet achieving this without a complete TextStreamer rewrite is not as easy. We can easily create an obvious hook-in method:
def on_new_token(self, token: str, stream_end: bool = False):This method is called by TextStreamer yet its subclasses can easily customize printing. The default implementation of on_new_token method simply prints tokens to stdout as it currently does.
I don't foresee any major documentation updates as a consequence of this PR.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@gante @sgugger