Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bedrock component handling AWS constants #4514

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/backend/base/langflow/base/models/aws_constants.py
Original file line number Diff line number Diff line change
@@ -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",
]
42 changes: 6 additions & 36 deletions src/backend/base/langflow/components/embeddings/amazon_bedrock.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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(
Expand Down
78 changes: 9 additions & 69 deletions src/backend/base/langflow/components/models/amazon_bedrock.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.",
),
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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(
Expand Down
Loading