Spaces:
Runtime error
Runtime error
Greg Thompson
commited on
Commit
•
15a3232
1
Parent(s):
702b41e
Update logging to include nlu_response object
Browse files- app.py +10 -8
- mathtext_fastapi/nlu.py +3 -2
app.py
CHANGED
@@ -68,16 +68,18 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
68 |
|
69 |
# Handles if a student answer is already an integer or a float (ie., 8)
|
70 |
if type(message_text) == int or type(message_text) == float:
|
71 |
-
|
72 |
-
|
|
|
73 |
|
74 |
# Removes whitespace and converts str to arr to handle multiple numbers
|
75 |
message_text_arr = re.split(", |,| ", message_text.strip())
|
76 |
|
77 |
# Handle if a student answer is a string of numbers (ie., "8,9, 10")
|
78 |
if all(ele.isdigit() for ele in message_text_arr):
|
79 |
-
|
80 |
-
|
|
|
81 |
|
82 |
student_response_arr = []
|
83 |
|
@@ -93,13 +95,13 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
93 |
sentiment_api_resp = sentiment(message_text)
|
94 |
# [{'label': 'POSITIVE', 'score': 0.991188645362854}]
|
95 |
sent_data_dict = {'type': 'sentiment', 'data': sentiment_api_resp[0]['label']}
|
96 |
-
|
97 |
else:
|
98 |
if len(student_response_arr) > 1:
|
99 |
-
|
100 |
else:
|
101 |
-
|
102 |
|
103 |
# Uncomment to enable logging to Supabase
|
104 |
# prepare_message_data_for_logging(message_data, nlu_response)
|
105 |
-
return JSONResponse(content=
|
|
|
68 |
|
69 |
# Handles if a student answer is already an integer or a float (ie., 8)
|
70 |
if type(message_text) == int or type(message_text) == float:
|
71 |
+
nlu_response = {'type': 'integer', 'data': message_text, 'confidence': ''}
|
72 |
+
# prepare_message_data_for_logging(message_data, nlu_response)
|
73 |
+
return JSONResponse(content=nlu_response)
|
74 |
|
75 |
# Removes whitespace and converts str to arr to handle multiple numbers
|
76 |
message_text_arr = re.split(", |,| ", message_text.strip())
|
77 |
|
78 |
# Handle if a student answer is a string of numbers (ie., "8,9, 10")
|
79 |
if all(ele.isdigit() for ele in message_text_arr):
|
80 |
+
nlu_response = {'type': 'integer', 'data': ','.join(message_text_arr), 'confidence': ''}
|
81 |
+
# prepare_message_data_for_logging(message_data, nlu_response)
|
82 |
+
return JSONResponse(content=nlu_response)
|
83 |
|
84 |
student_response_arr = []
|
85 |
|
|
|
95 |
sentiment_api_resp = sentiment(message_text)
|
96 |
# [{'label': 'POSITIVE', 'score': 0.991188645362854}]
|
97 |
sent_data_dict = {'type': 'sentiment', 'data': sentiment_api_resp[0]['label']}
|
98 |
+
nlu_response = {'type': 'sentiment', 'data': 'negative', 'confidence': ''}
|
99 |
else:
|
100 |
if len(student_response_arr) > 1:
|
101 |
+
nlu_response = {'type': 'integer', 'data': ','.join(str(num) for num in student_response_arr), 'confidence': ''}
|
102 |
else:
|
103 |
+
nlu_response = {'type': 'integer', 'data': student_response_arr[0], 'confidence': ''}
|
104 |
|
105 |
# Uncomment to enable logging to Supabase
|
106 |
# prepare_message_data_for_logging(message_data, nlu_response)
|
107 |
+
return JSONResponse(content=nlu_response)
|
mathtext_fastapi/nlu.py
CHANGED
@@ -42,7 +42,7 @@ def get_or_create_supabase_entry(table_name, insert_data, check_variable=None):
|
|
42 |
|
43 |
|
44 |
|
45 |
-
def prepare_message_data_for_logging(message_data):
|
46 |
""" Builds the message data for each table and ensures it's logged to the database
|
47 |
|
48 |
Input:
|
@@ -73,7 +73,8 @@ def prepare_message_data_for_logging(message_data):
|
|
73 |
'channel_type': "whatsapp / turn.io",
|
74 |
'message_inserted_at': message_data['message']['_vnd']['v1']['chat']['inserted_at'],
|
75 |
'message_modified_at': message_data['message']['_vnd']['v1']['chat']['updated_at'],
|
76 |
-
'message_sent_at': format_datetime_in_isoformat(datetime.now())
|
|
|
77 |
# Autogenerated fields: created_at, modified_at
|
78 |
}
|
79 |
message_data_log = log_message_data_through_supabase_api('message', message_data)
|
|
|
42 |
|
43 |
|
44 |
|
45 |
+
def prepare_message_data_for_logging(message_data, nlu_response):
|
46 |
""" Builds the message data for each table and ensures it's logged to the database
|
47 |
|
48 |
Input:
|
|
|
73 |
'channel_type': "whatsapp / turn.io",
|
74 |
'message_inserted_at': message_data['message']['_vnd']['v1']['chat']['inserted_at'],
|
75 |
'message_modified_at': message_data['message']['_vnd']['v1']['chat']['updated_at'],
|
76 |
+
'message_sent_at': format_datetime_in_isoformat(datetime.now()),
|
77 |
+
'nlu_response': nlu_response
|
78 |
# Autogenerated fields: created_at, modified_at
|
79 |
}
|
80 |
message_data_log = log_message_data_through_supabase_api('message', message_data)
|