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 lines323334353536373831 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, traces_sample_rate=1.0,)
app = FastAPI()1234567869101112131415130 unmodified lines1461471481491501511461471521531541551561571583 unmodified lines162163164157165166167168from logging import getLoggerimport re
from 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 re
log = getLogger(__name__)
ERROR_CODE = 32202
def 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 object log.info(f'Starting evaluate message: {message_data}') try: message_text = str(message_data.get('message_body', '')) except KeyError: message_text = '' 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 keywords intent_api_response = run_intent_classification(message_text)3 unmodified lines
number_api_resp = text2int(message_text.lower())
if number_api_resp == 32202: if number_api_resp == ERROR_CODE: # Run intent classification with logistic regression model predicted_label = predict_message_intent(message_text) if predicted_label['confidence'] > 0.01:app.py+1-1
mathtext_fastapi/nlu.py+12-4