Spaces:
Runtime error
Runtime error
Greg Thompson
commited on
Commit
·
6e3f695
1
Parent(s):
3022b4e
Update payload_is_valid to fix issue with date checking
Browse files- mathtext_fastapi/nlu.py +16 -9
- scripts/make_request.py +15 -12
mathtext_fastapi/nlu.py
CHANGED
|
@@ -157,7 +157,22 @@ def payload_is_valid(payload_object):
|
|
| 157 |
"""
|
| 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 |
return (
|
| 162 |
isinstance(payload_object, Mapping) and
|
| 163 |
isinstance(payload_object.get('author_id'), str) and
|
|
@@ -168,15 +183,7 @@ def payload_is_valid(payload_object):
|
|
| 168 |
isinstance(payload_object.get('message_id'), str) and
|
| 169 |
isinstance(payload_object.get('message_inserted_at'), str) and
|
| 170 |
isinstance(payload_object.get('message_updated_at'), str) and
|
| 171 |
-
isinstance(payload_object.get('message_inserted_at'), str)
|
| 172 |
-
isinstance(
|
| 173 |
-
isoparse(payload_object.get('message_inserted_at')),
|
| 174 |
-
dt.datetime
|
| 175 |
-
) and
|
| 176 |
-
isinstance(
|
| 177 |
-
isoparse(payload_object.get('message_updated_at')),
|
| 178 |
-
dt.datetime
|
| 179 |
-
)
|
| 180 |
)
|
| 181 |
|
| 182 |
|
|
|
|
| 157 |
"""
|
| 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 |
+
>>> 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'}
|
| 162 |
+
False
|
| 163 |
"""
|
| 164 |
+
try:
|
| 165 |
+
isinstance(
|
| 166 |
+
isoparse(payload_object.get('message_inserted_at')),
|
| 167 |
+
dt.datetime
|
| 168 |
+
)
|
| 169 |
+
isinstance(
|
| 170 |
+
isoparse(payload_object.get('message_updated_at')),
|
| 171 |
+
dt.datetime
|
| 172 |
+
)
|
| 173 |
+
except ValueError:
|
| 174 |
+
return False
|
| 175 |
+
|
| 176 |
return (
|
| 177 |
isinstance(payload_object, Mapping) and
|
| 178 |
isinstance(payload_object.get('author_id'), str) and
|
|
|
|
| 183 |
isinstance(payload_object.get('message_id'), str) and
|
| 184 |
isinstance(payload_object.get('message_inserted_at'), str) and
|
| 185 |
isinstance(payload_object.get('message_updated_at'), str) and
|
| 186 |
+
isinstance(payload_object.get('message_inserted_at'), str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
)
|
| 188 |
|
| 189 |
|
scripts/make_request.py
CHANGED
|
@@ -48,18 +48,21 @@ def run_simulated_request(endpoint, sample_answer, context=None):
|
|
| 48 |
print(f"Case: {sample_answer}")
|
| 49 |
b_string = add_message_text_to_sample_object(sample_answer)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
# run_simulated_request('intent-classification', 'exit')
|
|
|
|
| 48 |
print(f"Case: {sample_answer}")
|
| 49 |
b_string = add_message_text_to_sample_object(sample_answer)
|
| 50 |
|
| 51 |
+
print("BSTRING")
|
| 52 |
+
print(b_string)
|
| 53 |
+
|
| 54 |
+
# if endpoint == 'sentiment-analysis' or endpoint == 'text2int' or endpoint =='intent-classification':
|
| 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')
|