mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
a91181fe6d
Added support for optionally supplying 'Guardrails for Amazon Bedrock' on both types of model invocations (batch/regular and streaming) and for all models supported by the Amazon Bedrock service. @baskaryan @hwchase17 ```python llm = Bedrock(model_id="<model_id>", client=bedrock, model_kwargs={}, guardrails={"id": " <guardrail_id>", "version": "<guardrail_version>", "trace": True}, callbacks=[BedrockAsyncCallbackHandler()]) class BedrockAsyncCallbackHandler(AsyncCallbackHandler): """Async callback handler that can be used to handle callbacks from langchain.""" async def on_llm_error( self, error: BaseException, **kwargs: Any, ) -> Any: reason = kwargs.get("reason") if reason == "GUARDRAIL_INTERVENED": # kwargs contains additional trace information sent by 'Guardrails for Bedrock' service. print(f"""Guardrails: {kwargs}""") # streaming llm = Bedrock(model_id="<model_id>", client=bedrock, model_kwargs={}, streaming=True, guardrails={"id": "<guardrail_id>", "version": "<guardrail_version>"}) ``` --------- Co-authored-by: Bagatur <baskaryan@gmail.com> |
||
---|---|---|
.. | ||
adapters | ||
agent_toolkits | ||
callbacks | ||
chat_loaders | ||
chat_message_histories | ||
chat_models | ||
docstore | ||
document_loaders | ||
document_transformers | ||
embeddings | ||
graphs | ||
indexes | ||
llms | ||
output_parsers | ||
retrievers | ||
storage | ||
tools | ||
utilities | ||
utils | ||
vectorstores | ||
__init__.py | ||
cache.py | ||
py.typed |