From 3d5514af0442426927029a68e15f25b21e8da6b1 Mon Sep 17 00:00:00 2001 From: Meenakshi Ruia Date: Wed, 25 Dec 2024 23:28:58 +0530 Subject: [PATCH 1/2] community/chat_models/bedrock.py - added yield after callback --- libs/community/langchain_community/chat_models/bedrock.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chat_models/bedrock.py b/libs/community/langchain_community/chat_models/bedrock.py index 6b36208390379..35ad534c165d4 100644 --- a/libs/community/langchain_community/chat_models/bedrock.py +++ b/libs/community/langchain_community/chat_models/bedrock.py @@ -264,7 +264,10 @@ def _stream( **kwargs, ): delta = chunk.text - yield ChatGenerationChunk(message=AIMessageChunk(content=delta)) + cg_chunk = ChatGenerationChunk(message=AIMessageChunk(content=delta)) + if run_manager: + run_manager.on_llm_new_token(delta, chunk = cg_chunk ) + yield cg_chunk def _generate( self, From e412042482321755926d1be059fa3250abf26285 Mon Sep 17 00:00:00 2001 From: Meenakshi Ruia Date: Wed, 25 Dec 2024 23:54:06 +0530 Subject: [PATCH 2/2] community[patch]/chat_models/bedrock.py yielded after on_llm_new_token --- libs/community/langchain_community/chat_models/bedrock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chat_models/bedrock.py b/libs/community/langchain_community/chat_models/bedrock.py index 35ad534c165d4..8f4943951d5d5 100644 --- a/libs/community/langchain_community/chat_models/bedrock.py +++ b/libs/community/langchain_community/chat_models/bedrock.py @@ -266,7 +266,7 @@ def _stream( delta = chunk.text cg_chunk = ChatGenerationChunk(message=AIMessageChunk(content=delta)) if run_manager: - run_manager.on_llm_new_token(delta, chunk = cg_chunk ) + run_manager.on_llm_new_token(delta, chunk=cg_chunk ) yield cg_chunk def _generate(