From 296d00656b3a629570412c030d3987e3b4fd91fd Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Tue, 12 Nov 2024 09:46:37 -0500 Subject: [PATCH] fix: bedrock component handling AWS constants (#4514) * update model list as constants update model list as constants Add default value to Secret string variables * Update amazon_bedrock.py load_from_db false for session_token --- .../langflow/base/models/aws_constants.py | 70 +++++++++++++++++ .../components/embeddings/amazon_bedrock.py | 42 ++-------- .../components/models/amazon_bedrock.py | 78 +++---------------- 3 files changed, 85 insertions(+), 105 deletions(-) create mode 100644 src/backend/base/langflow/base/models/aws_constants.py diff --git a/src/backend/base/langflow/base/models/aws_constants.py b/src/backend/base/langflow/base/models/aws_constants.py new file mode 100644 index 000000000000..6a2d39e90450 --- /dev/null +++ b/src/backend/base/langflow/base/models/aws_constants.py @@ -0,0 +1,70 @@ +AWS_MODEL_IDs = [ + "amazon.titan-text-express-v1", + "amazon.titan-text-lite-v1", + "amazon.titan-text-premier-v1:0", + "amazon.titan-embed-text-v1", + "amazon.titan-embed-text-v2:0", + "amazon.titan-embed-image-v1", + "amazon.titan-image-generator-v1", + "anthropic.claude-v2", + "anthropic.claude-v2:1", + "anthropic.claude-3-sonnet-20240229-v1:0", + "anthropic.claude-3-haiku-20240307-v1:0", + "anthropic.claude-3-opus-20240229-v1:0", + "anthropic.claude-instant-v1", + "ai21.j2-mid-v1", + "ai21.j2-ultra-v1", + "cohere.command-text-v14", + "cohere.command-light-text-v14", + "cohere.command-r-v1:0", + "cohere.command-r-plus-v1:0", + "cohere.embed-english-v3", + "cohere.embed-multilingual-v3", + "meta.llama2-13b-chat-v1", + "meta.llama2-70b-chat-v1", + "meta.llama3-8b-instruct-v1:0", + "meta.llama3-70b-instruct-v1:0", + "mistral.mistral-7b-instruct-v0:2", + "mistral.mixtral-8x7b-instruct-v0:1", + "mistral.mistral-large-2402-v1:0", + "mistral.mistral-small-2402-v1:0", + "stability.stable-diffusion-xl-v0", + "stability.stable-diffusion-xl-v1", +] + +AWS_REGIONS = [ + "us-west-2", + "us-west-1", + "us-gov-west-1", + "us-gov-east-1", + "us-east-2", + "us-east-1", + "sa-east-1", + "me-south-1", + "me-central-1", + "il-central-1", + "eu-west-3", + "eu-west-2", + "eu-west-1", + "eu-south-2", + "eu-south-1", + "eu-north-1", + "eu-central-2", + "eu-central-1", + "cn-northwest-1", + "cn-north-1", + "ca-west-1", + "ca-central-1", + "ap-southeast-5", + "ap-southeast-4", + "ap-southeast-3", + "ap-southeast-2", + "ap-southeast-1", + "ap-south-2", + "ap-south-1", + "ap-northeast-3", + "ap-northeast-2", + "ap-northeast-1", + "ap-east-1", + "af-south-1", +] diff --git a/src/backend/base/langflow/components/embeddings/amazon_bedrock.py b/src/backend/base/langflow/components/embeddings/amazon_bedrock.py index 54c72d89fc8a..edac257dfabb 100644 --- a/src/backend/base/langflow/components/embeddings/amazon_bedrock.py +++ b/src/backend/base/langflow/components/embeddings/amazon_bedrock.py @@ -1,3 +1,4 @@ +from langflow.base.models.aws_constants import AWS_REGIONS from langflow.base.models.model import LCModelComponent from langflow.field_typing import Embeddings from langflow.inputs import SecretStrInput @@ -22,12 +23,14 @@ class AmazonBedrockEmbeddingsComponent(LCModelComponent): display_name="AWS Access Key ID", info="The access key for your AWS account." "Usually set in Python code as the environment variable 'AWS_ACCESS_KEY_ID'.", + value="AWS_ACCESS_KEY_ID", ), SecretStrInput( name="aws_secret_access_key", display_name="AWS Secret Access Key", info="The secret key for your AWS account. " "Usually set in Python code as the environment variable 'AWS_SECRET_ACCESS_KEY'.", + value="AWS_SECRET_ACCESS_KEY", ), SecretStrInput( name="aws_session_token", @@ -36,6 +39,7 @@ class AmazonBedrockEmbeddingsComponent(LCModelComponent): info="The session key for your AWS account. " "Only needed for temporary credentials. " "Usually set in Python code as the environment variable 'AWS_SESSION_TOKEN'.", + value="AWS_SESSION_TOKEN", ), SecretStrInput( name="credentials_profile_name", @@ -44,47 +48,13 @@ class AmazonBedrockEmbeddingsComponent(LCModelComponent): info="The name of the profile to use from your " "~/.aws/credentials file. " "If not provided, the default profile will be used.", + value="AWS_CREDENTIALS_PROFILE_NAME", ), DropdownInput( name="region_name", display_name="Region Name", value="us-east-1", - options=[ - "us-west-2", - "us-west-1", - "us-gov-west-1", - "us-gov-east-1", - "us-east-2", - "us-east-1", - "sa-east-1", - "me-south-1", - "me-central-1", - "il-central-1", - "eu-west-3", - "eu-west-2", - "eu-west-1", - "eu-south-2", - "eu-south-1", - "eu-north-1", - "eu-central-2", - "eu-central-1", - "cn-northwest-1", - "cn-north-1", - "ca-west-1", - "ca-central-1", - "ap-southeast-5", - "ap-southeast-4", - "ap-southeast-3", - "ap-southeast-2", - "ap-southeast-1", - "ap-south-2", - "ap-south-1", - "ap-northeast-3", - "ap-northeast-2", - "ap-northeast-1", - "ap-east-1", - "af-south-1", - ], + options=AWS_REGIONS, info="The AWS region where your Bedrock resources are located.", ), MessageTextInput( diff --git a/src/backend/base/langflow/components/models/amazon_bedrock.py b/src/backend/base/langflow/components/models/amazon_bedrock.py index d56bef29d732..a9fea390699d 100644 --- a/src/backend/base/langflow/components/models/amazon_bedrock.py +++ b/src/backend/base/langflow/components/models/amazon_bedrock.py @@ -1,3 +1,4 @@ +from langflow.base.models.aws_constants import AWS_REGIONS, AWS_MODEL_IDs from langflow.base.models.model import LCModelComponent from langflow.field_typing import LanguageModel from langflow.inputs import MessageTextInput, SecretStrInput @@ -16,39 +17,7 @@ class AmazonBedrockComponent(LCModelComponent): DropdownInput( name="model_id", display_name="Model ID", - options=[ - "amazon.titan-text-express-v1", - "amazon.titan-text-lite-v1", - "amazon.titan-text-premier-v1:0", - "amazon.titan-embed-text-v1", - "amazon.titan-embed-text-v2:0", - "amazon.titan-embed-image-v1", - "amazon.titan-image-generator-v1", - "anthropic.claude-v2", - "anthropic.claude-v2:1", - "anthropic.claude-3-sonnet-20240229-v1:0", - "anthropic.claude-3-haiku-20240307-v1:0", - "anthropic.claude-3-opus-20240229-v1:0", - "anthropic.claude-instant-v1", - "ai21.j2-mid-v1", - "ai21.j2-ultra-v1", - "cohere.command-text-v14", - "cohere.command-light-text-v14", - "cohere.command-r-v1:0", - "cohere.command-r-plus-v1:0", - "cohere.embed-english-v3", - "cohere.embed-multilingual-v3", - "meta.llama2-13b-chat-v1", - "meta.llama2-70b-chat-v1", - "meta.llama3-8b-instruct-v1:0", - "meta.llama3-70b-instruct-v1:0", - "mistral.mistral-7b-instruct-v0:2", - "mistral.mixtral-8x7b-instruct-v0:1", - "mistral.mistral-large-2402-v1:0", - "mistral.mistral-small-2402-v1:0", - "stability.stable-diffusion-xl-v0", - "stability.stable-diffusion-xl-v1", - ], + options=AWS_MODEL_IDs, value="anthropic.claude-3-haiku-20240307-v1:0", info="List of available model IDs to choose from.", ), @@ -57,12 +26,14 @@ class AmazonBedrockComponent(LCModelComponent): display_name="AWS Access Key ID", info="The access key for your AWS account." "Usually set in Python code as the environment variable 'AWS_ACCESS_KEY_ID'.", + value="AWS_ACCESS_KEY_ID", ), SecretStrInput( name="aws_secret_access_key", display_name="AWS Secret Access Key", info="The secret key for your AWS account. " "Usually set in Python code as the environment variable 'AWS_SECRET_ACCESS_KEY'.", + value="AWS_SECRET_ACCESS_KEY", ), SecretStrInput( name="aws_session_token", @@ -71,6 +42,8 @@ class AmazonBedrockComponent(LCModelComponent): info="The session key for your AWS account. " "Only needed for temporary credentials. " "Usually set in Python code as the environment variable 'AWS_SESSION_TOKEN'.", + value="AWS_SESSION_TOKEN", + load_from_db=False, ), SecretStrInput( name="credentials_profile_name", @@ -79,47 +52,14 @@ class AmazonBedrockComponent(LCModelComponent): info="The name of the profile to use from your " "~/.aws/credentials file. " "If not provided, the default profile will be used.", + value="AWS_CREDENTIALS_PROFILE_NAME", + load_from_db=False, ), DropdownInput( name="region_name", display_name="Region Name", value="us-east-1", - options=[ - "us-west-2", - "us-west-1", - "us-gov-west-1", - "us-gov-east-1", - "us-east-2", - "us-east-1", - "sa-east-1", - "me-south-1", - "me-central-1", - "il-central-1", - "eu-west-3", - "eu-west-2", - "eu-west-1", - "eu-south-2", - "eu-south-1", - "eu-north-1", - "eu-central-2", - "eu-central-1", - "cn-northwest-1", - "cn-north-1", - "ca-west-1", - "ca-central-1", - "ap-southeast-5", - "ap-southeast-4", - "ap-southeast-3", - "ap-southeast-2", - "ap-southeast-1", - "ap-south-2", - "ap-south-1", - "ap-northeast-3", - "ap-northeast-2", - "ap-northeast-1", - "ap-east-1", - "af-south-1", - ], + options=AWS_REGIONS, info="The AWS region where your Bedrock resources are located.", ), DictInput(