Skip to content

The agent engineering platform.

community[patch]: Invoke callback prior to yielding token fix [HuggingFaceTextGenInference] (#20426)

balloonioe786da777468
diff --git a/libs/community/langchain_community/llms/huggingface_text_gen_inference.py b/libs/community/langchain_community/llms/huggingface_text_gen_inference.py
index 9f56a949c6..e053d17278 100644
--- a/libs/community/langchain_community/llms/huggingface_text_gen_inference.py
+++ b/libs/community/langchain_community/llms/huggingface_text_gen_inference.py
@@ -259,9 +259,10 @@ class HuggingFaceTextGenInference(LLM):
# 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:
@@ -295,9 +296,10 @@ class HuggingFaceTextGenInference(LLM):
# 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: