1 Answer
- Newest
- Most votes
- Most comments
0
Hello.
I'm not sure since I haven't seen the full code, but are you using the Text Completions API?
Amazon Bedrock's Text Completions API cannot use Claude-3-Sonnet etc. as of March 2024.
Only the following models are compatible.
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-text-completion.html
- Anthropic Claude Instant v1.2
- Anthropic Claude v2
- Anthropic Claude v2.1
For Messages API, you can use Claude-3-Sonnet etc. as shown below.
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages.html
import boto3
import json
def lambda_handler(event, context):
bedrock = boto3.client('bedrock-runtime', region_name = "us-east-1")
body = json.dumps(
{
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 1000,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text":"Hello My name is Riku"
}
]
}
]
}
)
modelId = 'anthropic.claude-3-sonnet-20240229-v1:0'
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())
answer = response_body["content"][0]["text"]
print(answer)
Relevant content
- asked 2 months ago
- asked a month ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated 5 days ago