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 9f56a949c6b..e053d172789 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: