Skip to content

Commit

Permalink
community[patch]: callback before yield for bedrock llm (#26804)
Browse files Browse the repository at this point in the history
**Description:** Moves yield to after callback for
`_prepare_input_and_invoke_stream` and
`_aprepare_input_and_invoke_stream` for bedrock llm in community
package.
**Issue:** #16913
  • Loading branch information
subroy13 authored Sep 24, 2024
1 parent e40a2b8 commit 997d95c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libs/community/langchain_community/llms/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,12 @@ def _prepare_input_and_invoke_stream(
for chunk in LLMInputOutputAdapter.prepare_output_stream(
provider, response, stop, True if messages else False
):
yield chunk
# verify and raise callback error if any middleware intervened
self._get_bedrock_services_signal(chunk.generation_info) # type: ignore[arg-type]

if run_manager is not None:
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
yield chunk

async def _aprepare_input_and_invoke_stream(
self,
Expand Down Expand Up @@ -703,13 +703,13 @@ async def _aprepare_input_and_invoke_stream(
async for chunk in LLMInputOutputAdapter.aprepare_output_stream(
provider, response, stop
):
yield chunk
if run_manager is not None and asyncio.iscoroutinefunction(
run_manager.on_llm_new_token
):
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
elif run_manager is not None:
run_manager.on_llm_new_token(chunk.text, chunk=chunk) # type: ignore[unused-coroutine]
yield chunk


@deprecated(
Expand Down

0 comments on commit 997d95c

Please sign in to comment.