generated from lambda-feedback/Evaluation-Function-Boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
54 lines (46 loc) · 1.55 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
import json
try:
from .src.module import chat_module
except ImportError:
from src.module import chat_module
def handler(event, context):
"""
Lambda handler function
"""
# Log the input event for debugging purposes
# print("Received event:", " ".join(json.dumps(event, indent=2).splitlines()))
if "body" in event:
try:
event = json.loads(event["body"])
except json.JSONDecodeError:
return {
"statusCode": 400,
"body": "Invalid JSON format in the body. Please check the input."
}
if "message" not in event:
return {
"statusCode": 400,
"body": "Missing 'message' key in event. Please confirm the key in the json body."
}
if "params" not in event:
return {
"statusCode": 400,
"body": "Missing 'params' key in event. Please confirm the key in the json body. Make sure it contains the necessary conversation_id."
}
message = event.get("message", None)
params = event.get("params", None)
try:
chatbot_response = chat_module(message, params)
except Exception as e:
return {
"statusCode": 500,
"body": f"An error occurred within the chat_module(): {str(e)}"
}
# Create a response
response = {
"statusCode": 200,
"body": chatbot_response
}
# Log the response for debugging purposes
print("Returning response:", " ".join(json.dumps(response, indent=2).splitlines()))
return response