From b1da532522f3142820e6b74283b272dd29d78702 Mon Sep 17 00:00:00 2001 From: Subhrajyoty Roy Date: Tue, 24 Sep 2024 23:25:52 +0530 Subject: [PATCH] community[patch]: callback before yield for deepsparse llm (#26822) **Description:** Moves yield to after callback for `_stream` and `_astream` function for the deepsparse model in the community package **Issue:** #16913 --- libs/community/langchain_community/llms/deepsparse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/llms/deepsparse.py b/libs/community/langchain_community/llms/deepsparse.py index 9375a3f7722..6a743cd5065 100644 --- a/libs/community/langchain_community/llms/deepsparse.py +++ b/libs/community/langchain_community/llms/deepsparse.py @@ -190,10 +190,10 @@ class DeepSparse(LLM): ) for token in inference: chunk = GenerationChunk(text=token.generations[0].text) - yield chunk if run_manager: run_manager.on_llm_new_token(token=chunk.text) + yield chunk async def _astream( self, @@ -228,7 +228,7 @@ class DeepSparse(LLM): ) for token in inference: chunk = GenerationChunk(text=token.generations[0].text) - yield chunk if run_manager: await run_manager.on_llm_new_token(token=chunk.text) + yield chunk