-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
39 lines (32 loc) · 1007 Bytes
/
lambda_function.py
File metadata and controls
39 lines (32 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import boto3
import json
bedrock = boto3.client(
service_name='bedrock-runtime',
region_name='us-east-1'
)
modelId = 'cohere.command-text-v14'
def lambda_handler(event, context):
print('Event: ', json.dumps(event))
requestBody = json.loads(event['body'])
prompt = requestBody['prompt']
body ={
'prompt': prompt,
'max_tokens': 400,
'temperature': 0.75,
'p': 0.01,
'k': 0,
'stop_sequences': [],
'return_likelihoods': 'NONE'
}
bedrockResponse = bedrock.invoke_model(modelId=modelId,
body=json.dumps(body),
accept='*/*',
contentType='application/json')
response = json.loads(bedrockResponse['body'].read())['generations'][0]['text']
apiResponse ={
'statusCode': 200,
'body': json.dumps({
'prompt': response
})
}
return apiResponse