Skip to content

The agent engineering platform.

community[patch]: callback before yield for textgen (#26929)

Subhrajyoty Royadcfecdb67a3
diff --git a/libs/community/langchain_community/llms/textgen.py b/libs/community/langchain_community/llms/textgen.py
index a9a100d402..33a4f74f97 100644
--- a/libs/community/langchain_community/llms/textgen.py
+++ b/libs/community/langchain_community/llms/textgen.py
@@ -335,14 +335,13 @@ class TextGen(LLM):
text=result["text"], # type: ignore[call-overload, index]
generation_info=None,
)
+ if run_manager:
+ run_manager.on_llm_new_token(token=chunk.text)
yield chunk
elif result["event"] == "stream_end": # type: ignore[call-overload, index]
websocket_client.close()
return
- if run_manager:
- run_manager.on_llm_new_token(token=chunk.text)
-
async def _astream(
self,
prompt: str,
@@ -408,10 +407,9 @@ class TextGen(LLM):
text=result["text"], # type: ignore[call-overload, index]
generation_info=None,
)
+ if run_manager:
+ await run_manager.on_llm_new_token(token=chunk.text)
yield chunk
elif result["event"] == "stream_end": # type: ignore[call-overload, index]
websocket_client.close()
return
-
- if run_manager:
- await run_manager.on_llm_new_token(token=chunk.text)