From cae27505fc5bde99c0ec32ad653df26c90aad5f2 Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Mon, 26 Jul 2021 21:50:14 +0200 Subject: [PATCH] Stop process if tag is 'dont_understand' and process the intent dynamically from the path --- main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d0961e4..6609cdc 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import flask from flask import Flask, request, jsonify, Response import ia.process -from utils import config_utils, flask_utils +from utils import config_utils, flask_utils, intents_utils, utils app = Flask(__name__) @@ -19,10 +19,19 @@ def process_request(): print("SENTENCE : " + sentence + " /// TAG : " + tag_for_request) - return jsonify(tag_for_request) + # stop here if the sentence isn't understood + if tag_for_request == 'dont_understand': + return jsonify("I didn't get that.") + + path_of_intent = intents_utils.get_path(tag_for_request) + path_of_intent = path_of_intent.split('/intents/')[1].replace('/', '.') + path_of_intent = "intents." + path_of_intent + "intent" + + method = utils.import_method_from_string(path_of_intent, tag_for_request) + return jsonify(method()) if __name__ == '__main__': # start the flask server app.config['JSON_AS_ASCII'] = False - app.run(port=config_utils.get_in_config("PORT"), debug=False, host='0.0.0.0', threaded=True) \ No newline at end of file + app.run(port=config_utils.get_in_config("PORT"), debug=False, host='0.0.0.0', threaded=True)