Greg Thompson commited on
Commit
28a310a
1 Parent(s): 4bff611

Update nlu endpoint to take b-string request object

Browse files
Files changed (2) hide show
  1. app.py +2 -1
  2. scripts/make_request.py +60 -58
app.py CHANGED
@@ -62,7 +62,8 @@ async def evaluate_user_message_with_nlu_api(request: Request):
62
  {'type':'sentiment', 'data': 'negative'}
63
  """
64
 
65
- message_data = await request.json()
 
66
  message_text = message_data['message']['text']['body'].lower()
67
 
68
  int_api_resp = text2int(message_text)
 
62
  {'type':'sentiment', 'data': 'negative'}
63
  """
64
 
65
+ data_dict = await request.json()
66
+ message_data = data_dict.get('message_data', '')
67
  message_text = message_data['message']['text']['body'].lower()
68
 
69
  int_api_resp = text2int(message_text)
scripts/make_request.py CHANGED
@@ -14,67 +14,69 @@ request = requests.post(url=
14
  print(request)
15
 
16
 
17
- json = {
18
- 'message': {
19
- '_vnd': {
20
- 'v1': {
21
- 'author': {
22
- 'id': 57787919091,
23
- 'name': 'GT',
24
- 'type': 'OWNER'
25
- },
26
- 'card_uuid': None,
27
- 'chat': {
28
- 'assigned_to': {
29
- 'id': 'jhk151kl-hj42-3752-3hjk-h4jk6hjkk2',
30
- 'name': 'Greg Thompson',
31
- 'type': 'OPERATOR'
32
- },
33
- 'contact_uuid': 'j43hk26-2hjl-43jk-hnk2-k4ljl46j0ds09',
34
- 'inserted_at': '2022-07-05T04:00:34.033522Z',
35
- 'owner': '+57787919091',
36
- 'permalink': 'https://app.turn.io/c/4kl209sd0-a7b8-2hj3-8563-3hu4a89b32',
37
- 'state': 'OPEN',
38
- 'state_reason': 'Re-opened by inbound message.',
39
- 'unread_count': 19,
40
- 'updated_at': '2023-01-10T02:37:28.487319Z',
41
- 'uuid': '4kl209sd0-a7b8-2hj3-8563-3hu4a89b32'
42
- },
43
- 'direction': 'inbound',
44
- 'faq_uuid': None,
45
- 'in_reply_to': None,
46
- 'inserted_at': '2023-01-10T02:37:28.477940Z',
47
- 'labels': [{
48
- 'confidence': 0.506479332,
49
- 'metadata': {
50
- 'nlu': {
51
- 'confidence': 0.506479332,
52
- 'intent': 'question',
53
- 'model_name': 'nlu-general-spacy-ngrams-20191014'
54
- }
55
- },
56
- 'uuid': 'ha7890s2k-hjk2-2476-s8d9-fh9779a8a9ds',
57
- 'value': 'Unclassified'
58
- }],
59
- 'last_status': None,
60
- 'last_status_timestamp': None,
61
- 'on_fallback_channel': False,
62
- 'rendered_content': None,
63
- 'uuid': 's8df79zhws-h89s-hj23-7s8d-thb248d9bh2qn'
64
- }
65
- },
66
- 'from': 57787919091,
67
- 'id': 'hsjkthzZGehkzs09sijWA3',
68
- 'text': {'body': 'eight'},
69
- 'timestamp': 1673318248,
70
- 'type': 'text'
71
- },
72
- 'type': 'message'
73
- }
 
 
74
 
75
  request = requests.post(url=
76
  'http://localhost:7860/nlu',
77
- json=json
78
  ).json()
79
 
80
  print(request)
 
14
  print(request)
15
 
16
 
17
+ # json = {
18
+ # 'message': {
19
+ # '_vnd': {
20
+ # 'v1': {
21
+ # 'author': {
22
+ # 'id': 57787919091,
23
+ # 'name': 'GT',
24
+ # 'type': 'OWNER'
25
+ # },
26
+ # 'card_uuid': None,
27
+ # 'chat': {
28
+ # 'assigned_to': {
29
+ # 'id': 'jhk151kl-hj42-3752-3hjk-h4jk6hjkk2',
30
+ # 'name': 'Greg Thompson',
31
+ # 'type': 'OPERATOR'
32
+ # },
33
+ # 'contact_uuid': 'j43hk26-2hjl-43jk-hnk2-k4ljl46j0ds09',
34
+ # 'inserted_at': '2022-07-05T04:00:34.033522Z',
35
+ # 'owner': '+57787919091',
36
+ # 'permalink': 'https://app.turn.io/c/4kl209sd0-a7b8-2hj3-8563-3hu4a89b32',
37
+ # 'state': 'OPEN',
38
+ # 'state_reason': 'Re-opened by inbound message.',
39
+ # 'unread_count': 19,
40
+ # 'updated_at': '2023-01-10T02:37:28.487319Z',
41
+ # 'uuid': '4kl209sd0-a7b8-2hj3-8563-3hu4a89b32'
42
+ # },
43
+ # 'direction': 'inbound',
44
+ # 'faq_uuid': None,
45
+ # 'in_reply_to': None,
46
+ # 'inserted_at': '2023-01-10T02:37:28.477940Z',
47
+ # 'labels': [{
48
+ # 'confidence': 0.506479332,
49
+ # 'metadata': {
50
+ # 'nlu': {
51
+ # 'confidence': 0.506479332,
52
+ # 'intent': 'question',
53
+ # 'model_name': 'nlu-general-spacy-ngrams-20191014'
54
+ # }
55
+ # },
56
+ # 'uuid': 'ha7890s2k-hjk2-2476-s8d9-fh9779a8a9ds',
57
+ # 'value': 'Unclassified'
58
+ # }],
59
+ # 'last_status': None,
60
+ # 'last_status_timestamp': None,
61
+ # 'on_fallback_channel': False,
62
+ # 'rendered_content': None,
63
+ # 'uuid': 's8df79zhws-h89s-hj23-7s8d-thb248d9bh2qn'
64
+ # }
65
+ # },
66
+ # 'from': 57787919091,
67
+ # 'id': 'hsjkthzZGehkzs09sijWA3',
68
+ # 'text': {'body': 'eight'},
69
+ # 'timestamp': 1673318248,
70
+ # 'type': 'text'
71
+ # },
72
+ # 'type': 'message'
73
+ # }
74
+
75
+ json = b'{"message_data": {"message":{"_vnd":{"v1":{"author":{"id":57787919091,"name":"GT","type":"OWNER"},"card_uuid":null,"chat":{"assigned_to":{"id":"jhk151kl-hj42-3752-3hjk-h4jk6hjkk2","name":"Greg Thompson","type":"OPERATOR"},"contact_uuid":"j43hk26-2hjl-43jk-hnk2-k4ljl46j0ds09","inserted_at":"2022-07-05T04:00:34.033522Z","owner":"+57787919091","permalink":"https://app.turn.io/c/4kl209sd0-a7b8-2hj3-8563-3hu4a89b32","state":"OPEN","state_reason":"Re-opened by inbound message.","unread_count":14,"updated_at":"2023-01-10T02:37:28.487319Z","uuid":"4kl209sd0-a7b8-2hj3-8563-3hu4a89b32"},"direction":"inbound","faq_uuid":null,"in_reply_to":null,"inserted_at":"2023-01-10T02:37:28.477940Z","labels":[{"confidence":0.506479332,"metadata":{"nlu":{"confidence":0.506479332,"intent":"question","model_name":"nlu-general-spacy-ngrams-20191014"}},"uuid":"ha7890s2k-hjk2-2476-s8d9-fh9779a8a9ds","value":"Unclassified"}],"last_status":null,"last_status_timestamp":null,"on_fallback_channel":false,"rendered_content":null,"uuid":"s8df79zhws-h89s-hj23-7s8d-thb248d9bh2qn"}},"from":57787919091,"id":"hsjkthzZGehkzs09sijWA3","text":{"body":"eight"},"timestamp":1673318248,"type":"text"},"type":"message"}}\n'
76
 
77
  request = requests.post(url=
78
  'http://localhost:7860/nlu',
79
+ data=json
80
  ).json()
81
 
82
  print(request)