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 lines69707172727374752 unmodified lines787980818182838410 unmodified lines9596979898991001011 unmodified line10310410510610610768 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) 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) prepare_message_data_for_logging(message_data, nlu_response, message_data) return JSONResponse(content=nlu_response)
student_response_arr = []10 unmodified lines sentiment_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': ''} 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 line nlu_response = {'type': 'integer', 'data': student_response_arr[0], 'confidence': ''}
# Uncomment to enable logging to Supabase # prepare_message_data_for_logging(message_data, nlu_response) prepare_message_data_for_logging(message_data, nlu_response, message_data) return JSONResponse(content=nlu_response)41 unmodified lines424344454546474825 unmodified lines74757677777879808141 unmodified lines
def prepare_message_data_for_logging(message_data, nlu_response):def 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 database
Input: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 '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