Skip to content

The agent engineering platform.

community[patch]: Invoke callback prior to yielding token fix for HuggingFaceEndpoint (#20366)

balloonio93caa568f91c
diff --git a/libs/community/langchain_community/llms/huggingface_endpoint.py b/libs/community/langchain_community/llms/huggingface_endpoint.py
index b4bbf96d82..290b2da963 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: