MCPcopy
hub / github.com/langchain-ai/langchain / Bedrock

Class Bedrock

libs/community/langchain_community/llms/bedrock.py:718–917  ·  view source on GitHub ↗

Bedrock models. To authenticate, the AWS client uses the following methods to automatically load credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html If a specific credential profile should be used, you must pass the name of the profile fr

Source from the content-addressed store, hash-verified

716 since="0.0.34", removal="0.3", alternative_import="langchain_aws.BedrockLLM"
717)
718class Bedrock(LLM, BedrockBase):
719 """Bedrock models.
720
721 To authenticate, the AWS client uses the following methods to
722 automatically load credentials:
723 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html
724
725 If a specific credential profile should be used, you must pass
726 the name of the profile from the ~/.aws/credentials file that is to be used.
727
728 Make sure the credentials / roles used have the required policies to
729 access the Bedrock service.
730 """
731
732 """
733 Example:
734 .. code-block:: python
735
736 from bedrock_langchain.bedrock_llm import BedrockLLM
737
738 llm = BedrockLLM(
739 credentials_profile_name="default",
740 model_id="amazon.titan-text-express-v1",
741 streaming=True
742 )
743
744 """
745
746 @root_validator()
747 def validate_environment(cls, values: Dict) -> Dict:
748 model_id = values["model_id"]
749 if model_id.startswith("anthropic.claude-3"):
750 raise ValueError(
751 "Claude v3 models are not supported by this LLM."
752 "Please use `from langchain_community.chat_models import BedrockChat` "
753 "instead."
754 )
755 return super().validate_environment(values)
756
757 @property
758 def _llm_type(self) -> str:
759 """Return type of llm."""
760 return "amazon_bedrock"
761
762 @classmethod
763 def is_lc_serializable(cls) -> bool:
764 """Return whether this model can be serialized by Langchain."""
765 return True
766
767 @classmethod
768 def get_lc_namespace(cls) -> List[str]:
769 """Get the namespace of the langchain object."""
770 return ["langchain", "llms", "bedrock"]
771
772 @property
773 def lc_attributes(self) -> Dict[str, Any]:
774 attributes: Dict[str, Any] = {}
775

Calls

no outgoing calls