Spaces:
Runtime error
Runtime error
Greg Thompson commited on
Commit ·
2286f04
1
Parent(s): a61d64f
Update nlu endpoint with additional logging
Browse filesFiles changed (2)
- app.py+1-1
- mathtext_fastapi/nlu.py+12-4
31 unmodified lines3233343536373831 unmodified lines# Set traces_sample_rate to 1.0 to capture 100%# of transactions for performance monitoring.# We recommend adjusting this value in production,traces_sample_rate=0.20,)app = FastAPI()31 unmodified lines3233343536373831 unmodified lines# Set traces_sample_rate to 1.0 to capture 100%# of transactions for performance monitoring.# We recommend adjusting this value in production,traces_sample_rate=1.0,)app = FastAPI()
12345678910130 unmodified lines1411421431441451461471481491503 unmodified lines154155156157158159160from fuzzywuzzy import fuzzfrom mathtext_fastapi.logging import prepare_message_data_for_loggingfrom mathtext.sentiment import sentimentfrom mathtext.text2int import text2intfrom mathtext_fastapi.intent_classification import create_intent_classification_model, retrieve_intent_classification_model, predict_message_intentimport redef build_nlu_response_object(type, data, confidence):""" Turns nlu results into an object to send back to Turn.io130 unmodified lines{'type': 'sentiment', 'data': 'NEGATIVE', 'confidence': 0.9997807145118713}"""# Keeps system working with two different inputs - full and filtered @event objecttry:message_text = str(message_data.get('message_body', ''))except KeyError:message_text = ''# Run intent classification only for keywordsintent_api_response = run_intent_classification(message_text)3 unmodified linesnumber_api_resp = text2int(message_text.lower())if number_api_resp == 32202:# Run intent classification with logistic regression modelpredicted_label = predict_message_intent(message_text)if predicted_label['confidence'] > 0.01:123456789101112131415130 unmodified lines1461471481491501511521531541551561571583 unmodified lines162163164165166167168from logging import getLoggerimport refrom fuzzywuzzy import fuzzfrom mathtext_fastapi.logging import prepare_message_data_for_loggingfrom mathtext.sentiment import sentimentfrom mathtext.text2int import text2intfrom mathtext_fastapi.intent_classification import create_intent_classification_model, retrieve_intent_classification_model, predict_message_intentlog = getLogger(__name__)ERROR_CODE = 32202def build_nlu_response_object(type, data, confidence):""" Turns nlu results into an object to send back to Turn.io130 unmodified lines{'type': 'sentiment', 'data': 'NEGATIVE', 'confidence': 0.9997807145118713}"""# Keeps system working with two different inputs - full and filtered @event objectlog.info(f'Starting evaluate message: {message_data}')try:message_text = str(message_data.get('message_body', ''))except:log.error(f'Invalid request payload: {message_data}')# use python logging system to do this//return {'type': 'error', 'data': ERROR_CODE, 'confidence': 0}# Run intent classification only for keywordsintent_api_response = run_intent_classification(message_text)3 unmodified linesnumber_api_resp = text2int(message_text.lower())if number_api_resp == ERROR_CODE:# Run intent classification with logistic regression modelpredicted_label = predict_message_intent(message_text)if predicted_label['confidence'] > 0.01:
app.py+1-1
mathtext_fastapi/nlu.py+12-4