You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/libs/community/langchain_community/llms
Harel Gal a91181fe6d
community[minor]: add support for Guardrails for Amazon Bedrock (#15099)
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>
7 months ago
..
grammars community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
__init__.py community[minor]: Adding Konko Completion endpoint (#15570) 7 months ago
ai21.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
aleph_alpha.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
amazon_api_gateway.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
anthropic.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
anyscale.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
aphrodite.py community[minor]: Add Aphrodite Engine support (#14759) 8 months ago
arcee.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
aviary.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
azureml_endpoint.py feat: adding paygo api support for Azure ML / Azure AI Studio (#14560) 7 months ago
baidu_qianfan_endpoint.py community:qianfan endpoint support init params & remove useless params definietion (#15381) 8 months ago
bananadev.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
baseten.py community: refactor Baseten integration with new API endpoints & docs (#15017) 8 months ago
beam.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
bedrock.py community[minor]: add support for Guardrails for Amazon Bedrock (#15099) 7 months ago
bittensor.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
cerebriumai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
chatglm.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
clarifai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
cloudflare_workersai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
cohere.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
ctransformers.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
ctranslate2.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
databricks.py community[patch]: Add param "task" to Databricks LLM to work around serialization of transform_output_fn (#14933) 8 months ago
deepinfra.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
deepsparse.py community[patch]: Fix generation_config not setting properly for DeepSparse (#15036) 8 months ago
edenai.py community: replace deprecated davinci models (#14860) 8 months ago
fake.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
fireworks.py docs: docstrings `langchain_community` update (#14889) 8 months ago
forefrontai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
gigachat.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
google_palm.py community[patch]: more deprecations (#15782) 8 months ago
gooseai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
gpt4all.py community[patch]: Enable streaming for GPT4all (#16392) 7 months ago
gradient_ai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
huggingface_endpoint.py community[patch]: added 'conversational' as a valid task for hugginface endopoint models (#15761) 7 months ago
huggingface_hub.py feat(llms): support more tasks in HuggingFaceHub LLM and remove deprecated dep (#14406) 7 months ago
huggingface_pipeline.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
huggingface_text_gen_inference.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
human.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
javelin_ai_gateway.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
koboldai.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
konko.py community[minor]: Adding Konko Completion endpoint (#15570) 7 months ago
llamacpp.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
loading.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
manifest.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
minimax.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
mlflow.py Remove unused `Params` (#14385) 8 months ago
mlflow_ai_gateway.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
modal.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
mosaicml.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
nlpcloud.py community[patch]: fix top_p type hint (#15452) 7 months ago
oci_data_science_model_deployment_endpoint.py docs, community[patch], experimental[patch], langchain[patch], cli[pa… (#15412) 8 months ago
octoai_endpoint.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
ollama.py community[patch]: fix ollama astream (#16070) 7 months ago
opaqueprompts.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
openai.py community[patch]: more deprecations (#15782) 8 months ago
openllm.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
openlm.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
pai_eas_endpoint.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
petals.py Refactor: use SecretStr for Petals llms (#15121) 8 months ago
pipelineai.py Refactor: use SecretStr for PipelineAI llms (#15120) 8 months ago
predibase.py Refactor: use SecretStr for Predibase llms (#15119) 8 months ago
predictionguard.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
promptlayer_openai.py Do not issue beta or deprecation warnings on internal calls (#15641) 8 months ago
replicate.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
rwkv.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
sagemaker_endpoint.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
self_hosted.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
self_hosted_hugging_face.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
stochasticai.py Refactor: use SecretStr for StochasticAI llms (#15118) 8 months ago
symblai_nebula.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
textgen.py docs: docstrings `langchain_community` update (#14889) 8 months ago
titan_takeoff.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
titan_takeoff_pro.py docs: docstrings `langchain_community` update (#14889) 8 months ago
together.py together[minor]: add llm (#15853) 8 months ago
tongyi.py Upgrades the Tongyi LLM and ChatTongyi Model (#14793) 8 months ago
utils.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
vertexai.py community[patch]: more deprecations (#15782) 8 months ago
vllm.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
volcengine_maas.py Refactor: use SecretStr for VolcEngineMaas llms (#15117) 8 months ago
watsonxllm.py community[patch]: fix stop (stop_sequences) param on WatsonxLLM (#15541) 7 months ago
writer.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
xinference.py docs: docstrings `langchain_community` update (#14889) 8 months ago
yandex.py community[patch]: use SecretStr for yandex model secrets (#15463) 7 months ago