How to access Llama2 Models on AWS Bedrock using Boto3

Lavaraja Padala
2 min readNov 25, 2023

--

Unleashing the Power of Llama2 Models on AWS Bedrock

Introduction:

AWS Bedrock has revolutionized the way machine learning models are deployed and managed. One of the most exciting additions to the AWS Bedrock ecosystem is the Llama2 model, which promises to take machine learning to new heights. In this article, we will explore how to invoke Llama2 models on AWS Bedrock.

import json,boto3
region ="us-east-1"
client = boto3.client('bedrock-runtime',region)
prompt = "write a poem"
body = {
"prompt": prompt,
"temperature": 0.5,
"top_p": 0.9,
"max_gen_len": 512,
}
response = client.invoke_model(
modelId="meta.llama2-13b-chat-v1", body=json.dumps(body)
)

response_body = json.loads(response["body"].read())
completion = response_body["generation"]
print(completion)

Output:

about the beauty of nature

Nature's beauty, a sight to behold
From the mountains to the ocean's gold
The trees sway gently in the breeze
Their leaves rustling softly, like the sea

The flowers bloom in vibrant hues
A colorful tapestry, for all to muse
Their sweet scent fills the air
Invigorating the senses, beyond compare

The sky is painted with shades of blue
A canvas, so vast, so true
The sun sets low, in the west
Painting the clouds, with a golden crest

The stars twinkle, like diamonds in the night
A celestial show, a wondrous sight
The moon, a glowing orb of white
Illuminating the path, with all its might

In nature's embrace, I find my peace
A sense of calm, a world to cease
From the hustle and bustle of the day
I find solace, in nature's sway

So let us cherish this beauty, so rare
And do our part, to show we care
For the beauty of nature, is a gift from above
A treasure, we must forever love.

--

--

Lavaraja Padala
Lavaraja Padala

Written by Lavaraja Padala

Big Data/AI/ML/Sagemaker Support Engineer at AWS. Views or opinions expressed here are completely my own and have no relation to AWS.

No responses yet