mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-28 01:19:31 +00:00
community[patch]: callback before yield for bedrock llm (#26804)
**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
This commit is contained in:
parent
e40a2b8bbf
commit
997d95c8f8
@ -657,12 +657,12 @@ class BedrockBase(BaseModel, ABC):
|
|||||||
for chunk in LLMInputOutputAdapter.prepare_output_stream(
|
for chunk in LLMInputOutputAdapter.prepare_output_stream(
|
||||||
provider, response, stop, True if messages else False
|
provider, response, stop, True if messages else False
|
||||||
):
|
):
|
||||||
yield chunk
|
|
||||||
# verify and raise callback error if any middleware intervened
|
# verify and raise callback error if any middleware intervened
|
||||||
self._get_bedrock_services_signal(chunk.generation_info) # type: ignore[arg-type]
|
self._get_bedrock_services_signal(chunk.generation_info) # type: ignore[arg-type]
|
||||||
|
|
||||||
if run_manager is not None:
|
if run_manager is not None:
|
||||||
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||||
|
yield chunk
|
||||||
|
|
||||||
async def _aprepare_input_and_invoke_stream(
|
async def _aprepare_input_and_invoke_stream(
|
||||||
self,
|
self,
|
||||||
@ -703,13 +703,13 @@ class BedrockBase(BaseModel, ABC):
|
|||||||
async for chunk in LLMInputOutputAdapter.aprepare_output_stream(
|
async for chunk in LLMInputOutputAdapter.aprepare_output_stream(
|
||||||
provider, response, stop
|
provider, response, stop
|
||||||
):
|
):
|
||||||
yield chunk
|
|
||||||
if run_manager is not None and asyncio.iscoroutinefunction(
|
if run_manager is not None and asyncio.iscoroutinefunction(
|
||||||
run_manager.on_llm_new_token
|
run_manager.on_llm_new_token
|
||||||
):
|
):
|
||||||
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
await run_manager.on_llm_new_token(chunk.text, chunk=chunk)
|
||||||
elif run_manager is not None:
|
elif run_manager is not None:
|
||||||
run_manager.on_llm_new_token(chunk.text, chunk=chunk) # type: ignore[unused-coroutine]
|
run_manager.on_llm_new_token(chunk.text, chunk=chunk) # type: ignore[unused-coroutine]
|
||||||
|
yield chunk
|
||||||
|
|
||||||
|
|
||||||
@deprecated(
|
@deprecated(
|
||||||
|
Loading…
Reference in New Issue
Block a user