Spaces:
Runtime error
Runtime error
Greg Thompson
commited on
Commit
•
1399a2f
1
Parent(s):
6e3f695
Update tests in nlu.py and make_request.py to reflect original b-string input
Browse files- mathtext_fastapi/nlu.py +1 -1
- scripts/make_request.py +43 -34
mathtext_fastapi/nlu.py
CHANGED
@@ -158,7 +158,7 @@ def payload_is_valid(payload_object):
|
|
158 |
>>> payload_is_valid({'author_id': '+5555555', 'author_type': 'OWNER', 'contact_uuid': '3246-43ad-faf7qw-zsdhg-dgGdg', 'message_body': 'thirty one', 'message_direction': 'inbound', 'message_id': 'SDFGGwafada-DFASHA4aDGA', 'message_inserted_at': '2022-07-05T04:00:34.03352Z', 'message_updated_at': '2023-04-06T10:08:23.745072Z'})
|
159 |
True
|
160 |
|
161 |
-
>>>
|
162 |
False
|
163 |
"""
|
164 |
try:
|
|
|
158 |
>>> payload_is_valid({'author_id': '+5555555', 'author_type': 'OWNER', 'contact_uuid': '3246-43ad-faf7qw-zsdhg-dgGdg', 'message_body': 'thirty one', 'message_direction': 'inbound', 'message_id': 'SDFGGwafada-DFASHA4aDGA', 'message_inserted_at': '2022-07-05T04:00:34.03352Z', 'message_updated_at': '2023-04-06T10:08:23.745072Z'})
|
159 |
True
|
160 |
|
161 |
+
>>> payload_is_valid({"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"})
|
162 |
False
|
163 |
"""
|
164 |
try:
|
scripts/make_request.py
CHANGED
@@ -44,26 +44,35 @@ def add_message_text_to_sample_object(message_text):
|
|
44 |
# """
|
45 |
|
46 |
|
47 |
-
def run_simulated_request(endpoint,
|
48 |
-
print(f"Case: {
|
49 |
-
|
|
|
50 |
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
# request = requests.post(
|
56 |
-
# url=f'http://localhost:7860/{endpoint}',
|
57 |
-
# json={'content': sample_answer}
|
58 |
-
# ).json()
|
59 |
-
# else:
|
60 |
-
# request = requests.post(
|
61 |
-
# url=f'http://localhost:7860/{endpoint}',
|
62 |
-
# data=b_string
|
63 |
-
# ).json()
|
64 |
|
65 |
-
# print(request)
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# run_simulated_request('intent-classification', 'exit')
|
69 |
# run_simulated_request('intent-classification', "I'm not sure")
|
@@ -80,24 +89,24 @@ def run_simulated_request(endpoint, sample_answer, context=None):
|
|
80 |
# run_simulated_request('intent-classification', "please stop")
|
81 |
# run_simulated_request('sentiment-analysis', 'I reject it')
|
82 |
# run_simulated_request('text2int', 'seven thousand nine hundred fifty seven')
|
83 |
-
run_simulated_request('nlu', 'test message')
|
84 |
-
run_simulated_request('nlu', 'eight')
|
85 |
-
run_simulated_request('nlu', 'is it 8')
|
86 |
-
run_simulated_request('nlu', 'can I know how its 0.5')
|
87 |
-
run_simulated_request('nlu', 'eight, nine, ten')
|
88 |
-
run_simulated_request('nlu', '8, 9, 10')
|
89 |
-
run_simulated_request('nlu', '8')
|
90 |
-
run_simulated_request('nlu', "I don't know")
|
91 |
-
run_simulated_request('nlu', "I don't know eight")
|
92 |
-
run_simulated_request('nlu', "I don't 9")
|
93 |
-
run_simulated_request('nlu', "0.2")
|
94 |
-
run_simulated_request('nlu', 'Today is a wonderful day')
|
95 |
-
run_simulated_request('nlu', 'IDK 5?')
|
96 |
-
run_simulated_request('nlu', 'hin')
|
97 |
-
run_simulated_request('nlu', 'exi')
|
98 |
-
run_simulated_request('nlu', 'easier')
|
99 |
-
run_simulated_request('nlu', 'stp')
|
100 |
-
run_simulated_request('nlu', '')
|
101 |
# run_simulated_request('manager', '')
|
102 |
# run_simulated_request('manager', 'add')
|
103 |
# run_simulated_request('manager', 'subtract')
|
|
|
44 |
# """
|
45 |
|
46 |
|
47 |
+
def run_simulated_request(endpoint, sample_payload, context=None):
|
48 |
+
print(f"Case: {sample_payload}")
|
49 |
+
# Used for testing full message object - deprecated April 7
|
50 |
+
# b_string = add_message_text_to_sample_object(sample_answer)
|
51 |
|
52 |
+
if endpoint == 'sentiment-analysis' or endpoint == 'text2int' or endpoint =='intent-classification':
|
53 |
+
request = requests.post(
|
54 |
+
url=f'http://localhost:7860/{endpoint}',
|
55 |
+
json={'content': sample_payload}
|
56 |
+
).json()
|
57 |
+
else:
|
58 |
+
request = requests.post(
|
59 |
+
url=f'http://localhost:7860/{endpoint}',
|
60 |
+
data=b_string
|
61 |
+
).json()
|
62 |
|
63 |
+
print(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
|
|
65 |
|
66 |
+
def run_full_nlu_endpoint_payload_test(sample_payload):
|
67 |
+
request = requests.post(
|
68 |
+
url=f'http://localhost:7860/nlu',
|
69 |
+
data=sample_payload
|
70 |
+
).json()
|
71 |
+
print(request)
|
72 |
+
|
73 |
+
|
74 |
+
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"}}')
|
75 |
+
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"}}')
|
76 |
|
77 |
# run_simulated_request('intent-classification', 'exit')
|
78 |
# run_simulated_request('intent-classification', "I'm not sure")
|
|
|
89 |
# run_simulated_request('intent-classification', "please stop")
|
90 |
# run_simulated_request('sentiment-analysis', 'I reject it')
|
91 |
# run_simulated_request('text2int', 'seven thousand nine hundred fifty seven')
|
92 |
+
# run_simulated_request('nlu', 'test message')
|
93 |
+
# run_simulated_request('nlu', 'eight')
|
94 |
+
# run_simulated_request('nlu', 'is it 8')
|
95 |
+
# run_simulated_request('nlu', 'can I know how its 0.5')
|
96 |
+
# run_simulated_request('nlu', 'eight, nine, ten')
|
97 |
+
# run_simulated_request('nlu', '8, 9, 10')
|
98 |
+
# run_simulated_request('nlu', '8')
|
99 |
+
# run_simulated_request('nlu', "I don't know")
|
100 |
+
# run_simulated_request('nlu', "I don't know eight")
|
101 |
+
# run_simulated_request('nlu', "I don't 9")
|
102 |
+
# run_simulated_request('nlu', "0.2")
|
103 |
+
# run_simulated_request('nlu', 'Today is a wonderful day')
|
104 |
+
# run_simulated_request('nlu', 'IDK 5?')
|
105 |
+
# run_simulated_request('nlu', 'hin')
|
106 |
+
# run_simulated_request('nlu', 'exi')
|
107 |
+
# run_simulated_request('nlu', 'easier')
|
108 |
+
# run_simulated_request('nlu', 'stp')
|
109 |
+
# run_simulated_request('nlu', '')
|
110 |
# run_simulated_request('manager', '')
|
111 |
# run_simulated_request('manager', 'add')
|
112 |
# run_simulated_request('manager', 'subtract')
|