Skip to content

Instantly share code, notes, and snippets.

@benoitMariaux
Created December 6, 2023 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoitMariaux/6690f19399dfdb67c05af9cbf7021cbe to your computer and use it in GitHub Desktop.
Save benoitMariaux/6690f19399dfdb67c05af9cbf7021cbe to your computer and use it in GitHub Desktop.
Amazon Bedrock invocation example in Python
import json
import boto3
my_session = boto3.session.Session()
my_region = my_session.region_name
# check you are in us-east-1 region (for now)
print(my_region)
bedrock_runtime = boto3.client('bedrock-runtime')
prompt = "Hello, how are you today?"
payload = json.dumps({
"inputText": prompt,
"textGenerationConfig" : {
"maxTokenCount": 512,
"stopSequences": [],
"temperature": 0.1,
"topP": 0.9
}
})
print(payload)
response = bedrock_runtime.invoke_model(
body=payload,
modelId="amazon.titan-tg1-large",
accept="application/json",
contentType="application/json"
)
response_body = json.loads(response['body'].read())
print(response_body['results'][0]['outputText'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment