diff --git a/libs/langchain/langchain/chat_models/bedrock.py b/libs/langchain/langchain/chat_models/bedrock.py index 5ae35736c5..642ef76cdf 100644 --- a/libs/langchain/langchain/chat_models/bedrock.py +++ b/libs/langchain/langchain/chat_models/bedrock.py @@ -41,6 +41,22 @@ class BedrockChat(BaseChatModel, BedrockBase): """Return type of chat model.""" return "amazon_bedrock_chat" + @classmethod + def is_lc_serializable(cls) -> bool: + """Return whether this model can be serialized by Langchain.""" + return True + + @property + def lc_attributes(self) -> Dict[str, Any]: + attributes: Dict[str, Any] = {} + + print(self.region_name) + + if self.region_name: + attributes["region_name"] = self.region_name + + return attributes + class Config: """Configuration for this pydantic object.""" diff --git a/libs/langchain/langchain/llms/bedrock.py b/libs/langchain/langchain/llms/bedrock.py index eba4afe1c2..a7fe68b042 100644 --- a/libs/langchain/langchain/llms/bedrock.py +++ b/libs/langchain/langchain/llms/bedrock.py @@ -12,6 +12,7 @@ from langchain.utilities.anthropic import ( get_num_tokens_anthropic, get_token_ids_anthropic, ) +from langchain.utils import get_from_dict_or_env HUMAN_PROMPT = "\n\nHuman:" ASSISTANT_PROMPT = "\n\nAssistant:" @@ -195,6 +196,13 @@ class BedrockBase(BaseModel, ABC): # use default credentials session = boto3.Session() + values["region_name"] = get_from_dict_or_env( + values, + "region_name", + "AWS_DEFAULT_REGION", + default=None, + ) + client_params = {} if values["region_name"]: client_params["region_name"] = values["region_name"] @@ -340,6 +348,20 @@ class Bedrock(LLM, BedrockBase): """Return type of llm.""" return "amazon_bedrock" + @classmethod + def is_lc_serializable(cls) -> bool: + """Return whether this model can be serialized by Langchain.""" + return True + + @property + def lc_attributes(self) -> Dict[str, Any]: + attributes: Dict[str, Any] = {} + + if self.region_name: + attributes["region_name"] = self.region_name + + return attributes + class Config: """Configuration for this pydantic object."""