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

Feature Request: Support Boto3 Client When Using BedrockEncoder #458

Open
drobbins-ancile opened this issue Oct 30, 2024 · 0 comments
Open

Comments

@drobbins-ancile
Copy link

drobbins-ancile commented Oct 30, 2024

Currently when instantiating a BedrockEncoder we are required to set the access key id, secret key, and session token. This is awkward and not ideal for long-running services like API's as the session credentials expire.

I am requesting that the BedrockEncoder support providing a boto3 client that is created outside of the encoder. This will support automatically refreshing the credentials and match the behavior of other frameworks that use the bedrock API.

It appears that there is already a client parameter available when creating a BedrockEncoder but it isn't used.

Perhaps we could support something like the following?

import boto3
from semantic_router.encoders import BedrockEncoder

boto3_client = boto3.client("bedrock-runtime")

encoder = BedrockEncoder(
	name="amazon.titan-embed-text-v2:0",
	client=boto3_client
)

The existing logic in the encoder would be modified to only create a new client if one is not provided:

import boto3
from semantic_router.encoders import BaseEncoder

class BedrockEncoder(BaseEncoder):
    client: boto3.client = None
	...


if not self.client:
      self.access_key_id = self.get_env_variable("AWS_ACCESS_KEY_ID", access_key_id)
      self.secret_access_key = self.get_env_variable(
          "AWS_SECRET_ACCESS_KEY", secret_access_key
      )
      self.session_token = self.get_env_variable("AWS_SESSION_TOKEN", session_token)
      self.region = self.get_env_variable(
          "AWS_DEFAULT_REGION", region, default="us-west-1"
      )
      self.input_type = input_type
      try:
          self.client = self._initialize_client(
              self.access_key_id,
              self.secret_access_key,
              self.session_token,
              self.region,
          )
      except Exception as e:
          raise ValueError(f"Bedrock client failed to initialise. Error: {e}") from e

The access_key_id, secret_access_key, and region parameters are already optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant