Spaces:
Runtime error
Runtime error
Greg Thompson
commited on
Commit
•
910034b
1
Parent(s):
7b3a151
Update Supabase logging with additional fields
Browse files- app.py +4 -4
- mathtext_fastapi/nlu.py +3 -2
app.py
CHANGED
@@ -69,7 +69,7 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
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 |
-
|
73 |
return JSONResponse(content=nlu_response)
|
74 |
|
75 |
# Removes whitespace and converts str to arr to handle multiple numbers
|
@@ -78,7 +78,7 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
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 |
-
|
82 |
return JSONResponse(content=nlu_response)
|
83 |
|
84 |
student_response_arr = []
|
@@ -95,7 +95,7 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
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': ''}
|
@@ -103,5 +103,5 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
103 |
nlu_response = {'type': 'integer', 'data': student_response_arr[0], 'confidence': ''}
|
104 |
|
105 |
# Uncomment to enable logging to Supabase
|
106 |
-
|
107 |
return JSONResponse(content=nlu_response)
|
|
|
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, message_data)
|
73 |
return JSONResponse(content=nlu_response)
|
74 |
|
75 |
# Removes whitespace and converts str to arr to handle multiple numbers
|
|
|
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, message_data)
|
82 |
return JSONResponse(content=nlu_response)
|
83 |
|
84 |
student_response_arr = []
|
|
|
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': sentiment_api_resp[0]['score']}
|
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': ''}
|
|
|
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, message_data)
|
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, nlu_response):
|
46 |
""" Builds the message data for each table and ensures it's logged to the database
|
47 |
|
48 |
Input:
|
@@ -74,7 +74,8 @@ def prepare_message_data_for_logging(message_data, nlu_response):
|
|
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)
|
|
|
42 |
|
43 |
|
44 |
|
45 |
+
def prepare_message_data_for_logging(message_data, nlu_response, request_object):
|
46 |
""" Builds the message data for each table and ensures it's logged to the database
|
47 |
|
48 |
Input:
|
|
|
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 |
+
'request_object': request_object
|
79 |
# Autogenerated fields: created_at, modified_at
|
80 |
}
|
81 |
message_data_log = log_message_data_through_supabase_api('message', message_data)
|