import boto3 | |
import json | |
import os | |
AWS_ACCESS_KEY = os.environ.get('AWS_ACCESS_KEY') | |
AWS_SECRET_KEY = os.environ.get('AWS_SECRET_KEY') | |
bedrock = boto3.client( | |
service_name="bedrock-runtime", | |
region_name="us-east-1", | |
aws_access_key_id=AWS_ACCESS_KEY, | |
aws_secret_access_key=AWS_SECRET_KEY | |
) | |
body = json.dumps({ | |
"max_tokens": 4096, | |
"messages": [{"role": "user", "content": "Hello, world"}], | |
"anthropic_version": "bedrock-2023-05-31" | |
}) | |
response = bedrock.invoke_model(body=body, modelId="anthropic.claude-3-5-sonnet-20240620-v1:0") | |
response_body = json.loads(response.get("body").read()) | |
print(response_body.get("content")) | |