-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (34 loc) · 1.08 KB
/
main.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import requests
import os
API_URL = os.environ['API_URL']
API_TOKEN = os.environ['API_TOKEN']
headers = {"Authorization": f"Bearer {API_TOKEN}"}
table = {
"Restaurant name": ["The Ji Spot", "Mr Due Stinky Tofu", "A Normal Beef Noodle Place", "A Spicy Beef Noodle Place"],
"features": ["takeout only, american, chicken biscuit, fast, high quality", "taiwanese, seating, good for families, cheap", "beef noodle soup, fast, high quality, seating", "spicy, beef noodle soup, seating, clean, expensive"],
}
def query(payload):
response = requests.post(
API_URL,
headers=headers,
json=payload,
timeout=10
)
return response.json()
def lambda_handler(event, context):
question = event['body']
output = query({
"inputs": {
"query": question,
"table": table,
}
})
return {
"statusCode": 200,
'headers': {'Content-Type': 'application/json'},
"body": json.dumps({
'answer': output,
'query': question,
})
}