Skip to content

Commit c0bf818

Browse files
committed
Updated
1 parent ab2c165 commit c0bf818

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: AWS_BedRockLLama3/main.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import boto3
2+
import json
3+
from botocore.exceptions import ClientError
4+
5+
def invoke_llama2(bedrock_runtime_client, prompt):
6+
try:
7+
body = {
8+
"prompt": prompt,
9+
"temperature": 0.5,
10+
"top_p": 0.9,
11+
"max_gen_len": 512,
12+
}
13+
14+
## Change Llama 3.1 model id from bedrock
15+
model_id = 'meta.llama3-8b-instruct-v1:0'
16+
response = bedrock_runtime_client.invoke_model(
17+
modelId=model_id, body=json.dumps(body)
18+
)
19+
20+
response_body = json.loads(response["body"].read())
21+
completion = response_body["generation"]
22+
23+
return completion
24+
25+
except ClientError:
26+
print("Couldn't invoke Llama 3")
27+
raise
28+
29+
brt = boto3.client(service_name='bedrock-runtime')
30+
result = invoke_llama2(brt, 'Explain Pythogorous Therom')
31+
print(result)

0 commit comments

Comments
 (0)