File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments