diff --git a/libs/community/langchain_community/llms/huggingface_endpoint.py b/libs/community/langchain_community/llms/huggingface_endpoint.py index b4bbf96d820..290b2da9633 100644 --- a/libs/community/langchain_community/llms/huggingface_endpoint.py +++ b/libs/community/langchain_community/llms/huggingface_endpoint.py @@ -326,9 +326,10 @@ class HuggingFaceEndpoint(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: @@ -361,9 +362,10 @@ class HuggingFaceEndpoint(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: