def talk(): values = request.get_json() human_chat = values.get('human_chat') name = values.get('bot_name') if human_chat is None: return "Error: You need to talk to me", 400 if name is None: return "Error: You need to tell me who i am", 400 filepath = "./bots/" + name + "/" + name if not os.path.exists(os.path.dirname(filepath)): return "Error: The name of the bot you specified is not found", 404 bot = ChatBot(name) bot_response = bot.response(human_chat) response = {'name': name, 'message': bot_response} return jsonify(response), 200
logger = init_log() bot = ChatBot() app = Flask(__name__, static_url_path='') ######################################## @app.route('/', methods=['GET', 'POST']) def view(): return render_template('index.html') @app.route('/chat', methods=['GET']) def response(): data = request.args.to_dict() message = data['message'] if message != '': answer = bot.response(message) return answer @app.route('/forget', methods=['GET']) def forget(): bot.forget() return 'success' if __name__ == '__main__': print bot.response('Server started...') app.run('127.0.0.1', debug=True)
app = Flask(__name__, static_url_path='') ######################################## @app.route('/', methods=['GET', 'POST']) def view(): return render_template('index.html') @app.route('/chat', methods=['GET']) def response(): data = request.args.to_dict() message = data['message'] if message != '': answer = bot.response(message) return answer @app.route('/forget', methods=['GET']) def forget(): bot.forget() return 'success' if __name__ == '__main__': print bot.response('四大美女') app.run('0.0.0.0', debug=True)