Greg Thompson commited on
Commit
8f01606
1 Parent(s): 30094ce

Update nlu endpoint with additionally logging around alternative decode process

Browse files
Files changed (2) hide show
  1. app.py +6 -2
  2. scripts/make_request.py +7 -7
app.py CHANGED
@@ -4,6 +4,7 @@ or
4
  `python -m uvicorn app:app --reload --host localhost --port 7860`
5
  """
6
  import ast
 
7
  from json import JSONDecodeError
8
  from logging import getLogger
9
  import mathactive.microlessons.num_one as num_one_quiz
@@ -151,7 +152,7 @@ def intent_classification_ep(content: Text = None):
151
  content = {"message": ml_response}
152
  return JSONResponse(content=content)
153
 
154
- import json
155
  @app.post("/nlu")
156
  async def evaluate_user_message_with_nlu_api(request: Request):
157
  """ Calls nlu evaluation and returns the nlu_response
@@ -166,7 +167,10 @@ async def evaluate_user_message_with_nlu_api(request: Request):
166
  """
167
  log.info(f'Received request: {request}')
168
  log.info(f'Request header: {request.headers}')
169
- log.info(f'Request body: {request.body()}')
 
 
 
170
 
171
  try:
172
  data_dict = await request.json()
 
4
  `python -m uvicorn app:app --reload --host localhost --port 7860`
5
  """
6
  import ast
7
+ import json
8
  from json import JSONDecodeError
9
  from logging import getLogger
10
  import mathactive.microlessons.num_one as num_one_quiz
 
152
  content = {"message": ml_response}
153
  return JSONResponse(content=content)
154
 
155
+
156
  @app.post("/nlu")
157
  async def evaluate_user_message_with_nlu_api(request: Request):
158
  """ Calls nlu evaluation and returns the nlu_response
 
167
  """
168
  log.info(f'Received request: {request}')
169
  log.info(f'Request header: {request.headers}')
170
+ request_body = await request.body()
171
+ log.info(f'Request body: {request_body}')
172
+ request_body_str = request_body.decode()
173
+ log.info(f'Request_body_str: {request_body_str}')
174
 
175
  try:
176
  data_dict = await request.json()
scripts/make_request.py CHANGED
@@ -71,17 +71,17 @@ def run_full_nlu_endpoint_payload_test(sample_payload):
71
  print(request)
72
 
73
 
74
- # Case: Wrong key
75
- run_full_nlu_endpoint_payload_test(b'{"message": {"author_id": "@event.message._vnd.v1.chat.owner", "author_type": "@event.message._vnd.v1.author.type", "contact_uuid": "@event.message._vnd.v1.chat.contact_uuid", "message_body": "@event.message.text.body", "message_direction": "@event.message._vnd.v1.direction", "message_id": "@event.message.id", "message_inserted_at": "@event.message._vnd.v1.chat.inserted_at", "message_updated_at": "@event.message._vnd.v1.chat.updated_at"}}')
76
 
77
- # Case: Correct payload
78
- run_full_nlu_endpoint_payload_test(b'{"message_data": {"author_id": "57787919091", "author_type": "OWNER", "contact_uuid": "df78gsdf78df", "message_body": "8", "message_direction": "inbound", "message_id": "dfgha789789ag9ga", "message_inserted_at": "2023-01-10T02:37:28.487319Z", "message_updated_at": "2023-01-10T02:37:28.487319Z"}}')
79
 
80
- # Case: Incorrect payload values
81
- run_full_nlu_endpoint_payload_test(b'{"message_data": {"author_id": "@event.message._vnd.v1.chat.owner", "author_type": "@event.message._vnd.v1.author.type", "contact_uuid": "@event.message._vnd.v1.chat.contact_uuid", "message_body": "@event.message.text.body", "message_direction": "@event.message._vnd.v1.direction", "message_id": "@event.message.id", "message_inserted_at": "@event.message._vnd.v1.chat.inserted_at", "message_updated_at": "@event.message._vnd.v1.chat.updated_at"}}')
82
 
83
  # Case: Wrong payload object
84
- run_full_nlu_endpoint_payload_test(b'{"message_data": {"_vnd": {"v1": {"author": {"id": 54327547257, "name": "Jin", "type": "OWNER"}, "card_uuid": None, "chat": {"assigned_to": None, "contact_uuid": "f7889-f78dfgb798-f786ah89g7-f78f9a", "inserted_at": "2023-03-28T13:21:47.581221Z", "owner": "+43789789146", "permalink": "", "state": "OPEN", "state_reason": "Re-opened by inbound message.", "unread_count": 97, "updated_at": "2023-04-07T21:05:27.389948Z", "uuid": "dfg9a78-d76a786dghas-78d9fga789g-a78d69a9"}, "direction": "inbound", "faq_uuid": None, "in_reply_to": None, "inserted_at": "2023-04-07T21:05:27.368580Z", "labels": [], "last_status": None, "last_status_timestamp": None, "on_fallback_channel": False, "rendered_content": None, "uuid": "hf78s7s89b-789fb68d9fg-789fb789dfb-f79sfb789"}}, "from": 5475248689, "id": "SBDE4zgAAy7887sfdT35SHFS", "text": {"body": 1000}, "timestamp": 1680901527, "type": "text"}, "type": "message"}')"
85
 
86
 
87
  # run_simulated_request('intent-classification', 'exit')
 
71
  print(request)
72
 
73
 
74
+ # # Case: Wrong key
75
+ # run_full_nlu_endpoint_payload_test(b'{"message": {"author_id": "@event.message._vnd.v1.chat.owner", "author_type": "@event.message._vnd.v1.author.type", "contact_uuid": "@event.message._vnd.v1.chat.contact_uuid", "message_body": "@event.message.text.body", "message_direction": "@event.message._vnd.v1.direction", "message_id": "@event.message.id", "message_inserted_at": "@event.message._vnd.v1.chat.inserted_at", "message_updated_at": "@event.message._vnd.v1.chat.updated_at"}}')
76
 
77
+ # # Case: Correct payload
78
+ # run_full_nlu_endpoint_payload_test(b'{"message_data": {"author_id": "57787919091", "author_type": "OWNER", "contact_uuid": "df78gsdf78df", "message_body": "8", "message_direction": "inbound", "message_id": "dfgha789789ag9ga", "message_inserted_at": "2023-01-10T02:37:28.487319Z", "message_updated_at": "2023-01-10T02:37:28.487319Z"}}')
79
 
80
+ # # Case: Incorrect payload values
81
+ # run_full_nlu_endpoint_payload_test(b'{"message_data": {"author_id": "@event.message._vnd.v1.chat.owner", "author_type": "@event.message._vnd.v1.author.type", "contact_uuid": "@event.message._vnd.v1.chat.contact_uuid", "message_body": "@event.message.text.body", "message_direction": "@event.message._vnd.v1.direction", "message_id": "@event.message.id", "message_inserted_at": "@event.message._vnd.v1.chat.inserted_at", "message_updated_at": "@event.message._vnd.v1.chat.updated_at"}}')
82
 
83
  # Case: Wrong payload object
84
+ run_full_nlu_endpoint_payload_test(b'{"message_data": {"_vnd": {"v1": {"author": {"id": 54327547257, "name": "Jin", "type": "OWNER"}, "card_uuid": None, "chat": {"assigned_to": None, "contact_uuid": "f7889-f78dfgb798-f786ah89g7-f78f9a", "inserted_at": "2023-03-28T13:21:47.581221Z", "owner": "+43789789146", "permalink": "", "state": "OPEN", "state_reason": "Re-opened by inbound message.", "unread_count": 97, "updated_at": "2023-04-07T21:05:27.389948Z", "uuid": "dfg9a78-d76a786dghas-78d9fga789g-a78d69a9"}, "direction": "inbound", "faq_uuid": None, "in_reply_to": None, "inserted_at": "2023-04-07T21:05:27.368580Z", "labels": [], "last_status": None, "last_status_timestamp": None, "on_fallback_channel": False, "rendered_content": None, "uuid": "hf78s7s89b-789fb68d9fg-789fb789dfb-f79sfb789"}}, "from": 5475248689, "id": "SBDE4zgAAy7887sfdT35SHFS", "text": {"body": 1000}, "timestamp": 1680901527, "type": "text"}, "type": "message"}')
85
 
86
 
87
  # run_simulated_request('intent-classification', 'exit')