Using AWS Bedrock with Flowstack

AWS Bedrock can be integrated with Flowstack, but currently, only the Python SDK implementation is available. REST API and Node.js SDK implementations are not provided.

Python SDK Implementation

To use AWS Bedrock with Flowstack in Python, follow these steps:

  1. Install Boto3 : Ensure you have the Boto3 library installed. Boto3 is the Amazon Web Services (AWS) SDK for Python.
pip install boto3
  1. Python Code Implementation : Use the following Python code to set up the AWS Bedrock client and make a request. Replace "YOUR_AWS_ACCESS_KEY_ID" and "YOUR_AWS_SECRET_ACCESS_KEY" with your AWS credentials.
import boto3
import json

def _add_header(request, **kwargs):
    request.headers.add_header('Flowstack-Auth', 'Bearer YOUR_FLOWSTACK_KEY')
    request.headers.add_header('AWS-Secret-Access-Key', "YOUR_AWS_SECRET_ACCESS_KEY")

bedrock = boto3.client(service_name='bedrock-runtime', 
                        region_name='us-east-1', 
                        endpoint_url='https://aws-bedrock.flowstack.ai',
                        aws_access_key_id="YOUR_AWS_ACCESS_KEY_ID",
                        aws_secret_access_key="YOUR_AWS_SECRET_ACCESS_KEY")

event_system = bedrock.meta.events
event_system.register_first('before-sign.*.*', _add_header)
modelId = 'your-model-id' # Replace with your model ID

body = json.dumps({
    "prompt": "Your prompt here", 
    "maxTokens": 200,
    "temperature": 0.5,
    "topP": 0.5
})

response = bedrock.invoke_model(
    modelId=modelId,
    body=body
)

response.get('body').read()

Replace "YOUR_FLOWSTACK_KEY" and "your-model-id" with the appropriate Flowstack key and model ID.