Skip to content

Instantly share code, notes, and snippets.

@darko-mesaros
Created August 21, 2024 15:37
Show Gist options
  • Save darko-mesaros/bc28d2dff0de74d17472703be47e1a3a to your computer and use it in GitHub Desktop.
Save darko-mesaros/bc28d2dff0de74d17472703be47e1a3a to your computer and use it in GitHub Desktop.
Amazon Bedrock converse API invocation
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