Skip to content

Commit

Permalink
community[patch]: Invoke callback prior to yielding token fix [Huggin…
Browse files Browse the repository at this point in the history
…gFaceTextGenInference] (#20426)

…gFaceTextGenInference)

- [x] **PR title**: community[patch]: Invoke callback prior to yielding
token fix for [HuggingFaceTextGenInference]


- [x] **PR message**: 
- **Description:** Invoke callback prior to yielding token in stream
method in [HuggingFaceTextGenInference]
    - **Issue:** #16913
    - **Dependencies:** None
    - **Twitter handle:** @bolun_zhang

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, hwchase17.

---------

Co-authored-by: Chester Curme <[email protected]>
  • Loading branch information
balloonio and ccurme authored Apr 18, 2024
1 parent 2d6d796 commit e786da7
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ def _stream(
# yield text, if any
if text:
chunk = GenerationChunk(text=text)
yield chunk

if run_manager:
run_manager.on_llm_new_token(chunk.text)
yield chunk

# break if stop sequence found
if stop_seq_found:
Expand Down Expand Up @@ -295,9 +296,10 @@ async def _astream(
# yield text, if any
if text:
chunk = GenerationChunk(text=text)
yield chunk

if run_manager:
await run_manager.on_llm_new_token(chunk.text)
yield chunk

# break if stop sequence found
if stop_seq_found:
Expand Down

0 comments on commit e786da7

Please sign in to comment.