Spaces:
Runtime error
Runtime error
Greg Thompson commited on
Commit ·
64c0031
1
Parent(s): 15a3232
Update Supabase logging with additional fields
Browse filesFiles changed (2)
- app.py+4-4
- mathtext_fastapi/nlu.py+3-2
68 unmodified lines697071727374752 unmodified lines7879808182838410 unmodified lines95969798991001011 unmodified line10310410510610768 unmodified lines# Handles if a student answer is already an integer or a float (ie., 8)if type(message_text) == int or type(message_text) == float:nlu_response = {'type': 'integer', 'data': message_text, 'confidence': ''}# prepare_message_data_for_logging(message_data, nlu_response)return JSONResponse(content=nlu_response)# Removes whitespace and converts str to arr to handle multiple numbers2 unmodified lines# Handle if a student answer is a string of numbers (ie., "8,9, 10")if all(ele.isdigit() for ele in message_text_arr):nlu_response = {'type': 'integer', 'data': ','.join(message_text_arr), 'confidence': ''}# prepare_message_data_for_logging(message_data, nlu_response)return JSONResponse(content=nlu_response)student_response_arr = []10 unmodified linessentiment_api_resp = sentiment(message_text)# [{'label': 'POSITIVE', 'score': 0.991188645362854}]sent_data_dict = {'type': 'sentiment', 'data': sentiment_api_resp[0]['label']}nlu_response = {'type': 'sentiment', 'data': 'negative', 'confidence': ''}else:if len(student_response_arr) > 1:nlu_response = {'type': 'integer', 'data': ','.join(str(num) for num in student_response_arr), 'confidence': ''}1 unmodified linenlu_response = {'type': 'integer', 'data': student_response_arr[0], 'confidence': ''}# Uncomment to enable logging to Supabase# prepare_message_data_for_logging(message_data, nlu_response)return JSONResponse(content=nlu_response)68 unmodified lines697071727374752 unmodified lines7879808182838410 unmodified lines95969798991001011 unmodified line10310410510610768 unmodified lines# Handles if a student answer is already an integer or a float (ie., 8)if type(message_text) == int or type(message_text) == float:nlu_response = {'type': 'integer', 'data': message_text, 'confidence': ''}prepare_message_data_for_logging(message_data, nlu_response, message_data)return JSONResponse(content=nlu_response)# Removes whitespace and converts str to arr to handle multiple numbers2 unmodified lines# Handle if a student answer is a string of numbers (ie., "8,9, 10")if all(ele.isdigit() for ele in message_text_arr):nlu_response = {'type': 'integer', 'data': ','.join(message_text_arr), 'confidence': ''}prepare_message_data_for_logging(message_data, nlu_response, message_data)return JSONResponse(content=nlu_response)student_response_arr = []10 unmodified linessentiment_api_resp = sentiment(message_text)# [{'label': 'POSITIVE', 'score': 0.991188645362854}]sent_data_dict = {'type': 'sentiment', 'data': sentiment_api_resp[0]['label']}nlu_response = {'type': 'sentiment', 'data': 'negative', 'confidence': sentiment_api_resp[0]['score']}else:if len(student_response_arr) > 1:nlu_response = {'type': 'integer', 'data': ','.join(str(num) for num in student_response_arr), 'confidence': ''}1 unmodified linenlu_response = {'type': 'integer', 'data': student_response_arr[0], 'confidence': ''}# Uncomment to enable logging to Supabaseprepare_message_data_for_logging(message_data, nlu_response, message_data)return JSONResponse(content=nlu_response)
41 unmodified lines4243444546474825 unmodified lines7475767778798041 unmodified linesdef prepare_message_data_for_logging(message_data, nlu_response):""" Builds the message data for each table and ensures it's logged to the databaseInput:25 unmodified lines'message_inserted_at': message_data['message']['_vnd']['v1']['chat']['inserted_at'],'message_modified_at': message_data['message']['_vnd']['v1']['chat']['updated_at'],'message_sent_at': format_datetime_in_isoformat(datetime.now()),'nlu_response': nlu_response# Autogenerated fields: created_at, modified_at}message_data_log = log_message_data_through_supabase_api('message', message_data)41 unmodified lines4243444546474825 unmodified lines747576777879808141 unmodified linesdef prepare_message_data_for_logging(message_data, nlu_response, request_object):""" Builds the message data for each table and ensures it's logged to the databaseInput:25 unmodified lines'message_inserted_at': message_data['message']['_vnd']['v1']['chat']['inserted_at'],'message_modified_at': message_data['message']['_vnd']['v1']['chat']['updated_at'],'message_sent_at': format_datetime_in_isoformat(datetime.now()),'nlu_response': nlu_response,'request_object': request_object# Autogenerated fields: created_at, modified_at}message_data_log = log_message_data_through_supabase_api('message', message_data)
app.py+4-4
mathtext_fastapi/nlu.py+3-2