-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
55 lines (47 loc) · 1.58 KB
/
index.py
File metadata and controls
55 lines (47 loc) · 1.58 KB
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
55
import json
try:
from .src.module import chat_module
from .src.agents.utils.types import JsonType
except ImportError:
from src.module import chat_module
from src.agents.utils.types import JsonType
def handler(event: JsonType, context):
"""
Lambda handler function
Args:
event (JsonType): The AWS Lambda event received by the gateway.
context (Any): The AWS Lambda context object.
"""
# Log the input event for debugging purposes
print("Received event:", json.dumps(event, indent=2))
if "body" not in event:
return {
"statusCode": 400,
"body": "Missing 'body' key in event. Please confirm the key in the json body."
}
body = json.loads(event["body"])
if "message" not in body:
return {
"statusCode": 400,
"body": "Missing 'message' key in event. Please confirm the key in the json body."
}
if "params" not in body:
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 = body["message"]
params = body["params"]
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": json.dumps(chatbot_response)
}
return response