Skip to content

The agent engineering platform.

community[patch]: Invoke callback prior to yielding token fix [DeepInfra] (#20427)

ballooniob66a4f48fa56
diff --git a/libs/community/langchain_community/llms/deepinfra.py b/libs/community/langchain_community/llms/deepinfra.py
index 412de97cf7..65911921a2 100644
--- a/libs/community/langchain_community/llms/deepinfra.py
+++ b/libs/community/langchain_community/llms/deepinfra.py
@@ -155,9 +155,9 @@ class DeepInfra(LLM):
for line in _parse_stream(response.iter_lines()):
chunk = _handle_sse_line(line)
if chunk:
- yield chunk
if run_manager:
run_manager.on_llm_new_token(chunk.text)
+ yield chunk
async def _astream(
self,
@@ -174,9 +174,9 @@ class DeepInfra(LLM):
async for line in _parse_stream_async(response.content):
chunk = _handle_sse_line(line)
if chunk:
- yield chunk
if run_manager:
await run_manager.on_llm_new_token(chunk.text)
+ yield chunk
def _parse_stream(rbody: Iterator[bytes]) -> Iterator[str]: