Created
August 21, 2024 15:37
-
-
Save darko-mesaros/bc28d2dff0de74d17472703be47e1a3a to your computer and use it in GitHub Desktop.
Amazon Bedrock converse API invocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
client = boto3.client('bedrock-runtime', region_name='us-east-1') | |
model_id = 'anthropic.claude-3-sonnet-20240229-v1:0' | |
user_message = "Who is Alan Ford, the comic book character?" | |
conversation = [ | |
{ | |
"role": "user", | |
"content": [{"text":user_message}], | |
} | |
] | |
response = client.converse( | |
modelId=model_id, | |
messages=conversation, | |
inferenceConfig={"maxTokens": 1024, "temperature": 0.5, "topP": 1}, | |
) | |
response_text = response["output"]["message"]["content"][0]["text"] | |
print(response_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment