Bedrock Runtime Python Client This repository contains a Python client for interacting with Bedrock, a platform for building and deploying AI models. With this client, you can easily send requests to Bedrock models and receive responses.
Installation To use this client, you need to have the following Python packages installed:
boto3: A Python SDK for AWS (Amazon Web Services). awscli: The AWS Command Line Interface. botocore: The low-level, core functionality of boto3. You can install these dependencies using pip by running the following command:
bash Copy code %pip install "boto3>=1.28.57" "awscli>=1.29.57" "botocore>=1.31.57" Getting Started To get started with this client, you will need to import the necessary libraries and create a connection to the Bedrock service.
python Copy code import boto3 import json
bedrock = boto3.client(service_name='bedrock-runtime') Next, you can prepare a request to send to a Bedrock model. In this example, we are sending a prompt to an AI model and receiving a response.
python Copy code
body = json.dumps({ "prompt": "\n\nHuman:explain black holes to 8th graders\n\nAssistant:", "max_tokens_to_sample": 300, "temperature": 0.1, "top_p": 0.9, })
modelId = 'anthropic.claude-v2'
accept = 'application/json' contentType = 'application/json'
response = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)
response_body = json.loads(response.get('body').read())
print(response_body.get('completion')) Make sure to customize the body, modelId, and other parameters according to your specific use case.
License This Python client for Bedrock is provided under the MIT License. Feel free to use and modify it as needed for your projects.