-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlambda_function.py
26 lines (24 loc) · 945 Bytes
/
lambda_function.py
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
import json
import boto3
def lambda_handler(event, context):
input1 = event.get('queryStringParameters')
input_question= list(input1)[0]
# TODO implement
#input_question = 'what is amazon bedrock?'
bedrock_runtime = boto3.client('bedrock-runtime',region_name='us-east-1')
response = bedrock_runtime.invoke_model(
modelId = 'amazon.titan-text-premier-v1:0',
body = json.dumps({'inputText':input_question})
)
body = json.loads(response.get('body').read())
outputText = body.get('results')[0].get('outputText')
return {
'statusCode': 200,
'body': json.dumps(str(outputText)),
'headers':{
'Content-Type':'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'PUT,POST,GET,OPTIONS',
'Access-Control-Allow-headers':'Content-Type',
}
}