def run_main_get_answer(request): if enc_vocab == None: chat_bot(request) req_dict = eval(request.data.decode('utf8')) user = req_dict['user'] project = req_dict['project'] question = req_dict['msg'] _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question, False, language) if answer_num == '': _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question + ' ', False, language) if len(answer_num.split(";")) > 1: answer = '해당 질문에 대한 답변이 하나 이상입니다. 좀더 구체적으로 부탁드립니다!' else: answer, _ = db_chat.get_answer_by_answer_num(user, project, answer_num) _, point = sentence_comparator.compare_by_formula(user, project, question, answer_num) v, e = voca_util.get_voca_and_entity_from_question(question, all_voca) word = ",".join(v) entity = "" for i in range(len(e)): if e[i] != None and e[i] != "": entity += e[i] if i < len(e) - 1: entity += "," res = {'answer': answer, 'point': point, 'word': word, 'entity': entity} return jsonify(res)
def reply_group_chat(request): user, project = request.form['user'], request.form['project'] question = request.form['msg'] question = question.lower() _, answer_num = run.run_rc_chatbot(enc_vocab, rev_dec_vocab, question, False, language) if answer_num == '': _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question + ' ', False, language) if len(answer_num.split(";")) > 1: answer = 'more than one answer!' else: answer, _ = db_chat.get_answer_by_answer_num(user, project, answer_num) res = {'answer' : answer} return jsonify(res)
def reply_dynamic_popup(request): user, project = request.form['user'], request.form['project'] question = request.form['msg'] question = question.lower() param_holder = eval(request.form['param_holder']) _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question, False, language) answer, _ = db_chat.get_answer_by_answer_num(user, project, answer_num) param = [param_holder] msg = [''] if answer[:1] == '$': param[0]['function_nm'] = answer.replace('\n', '').split(" ")[1] msg, _, _, param_holder = function_adapter.get_message_by_function(param, -1, 'Y') res = {'text' : msg[0]} return jsonify(res)
def reply_group_chat(request): user, project = request.form['user'], request.form['project'] question = request.form['msg'] _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question, False, language) if answer_num == '': _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question + ' ', False, language) if len(answer_num.split(";")) > 1: answer = '해당 질문에 대한 답변이 하나 이상입니다. 좀더 구체적으로 부탁드립니다!' else: answer, _ = db_chat.get_answer_by_answer_num(user, project, answer_num) image_path = faq_manager.get_image_path(user, project, answer_num) user_ip = request.remote_addr db_chat.collect_question(user_ip, question, answer_num) res = {'answer': answer, 'image_path': str(image_path)} return jsonify(res)
def run_main_get_answer(request): if enc_vocab == None: chat_bot(request) req_dict = eval(request.data.decode('utf8')) user = req_dict['user'] project = req_dict['project'] question = req_dict['msg'] _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question, False, language) if answer_num == '': _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, question + ' ', False, language) if len(answer_num.split(";")) > 1: answer = 'more than one answer!' else: answer, _ = db_chat.get_answer_by_answer_num(user, project, answer_num) _, point = sentence_comparator.compare_by_formula(user, project, question, answer_num) res = {'answer' : answer, 'point' : point} return jsonify(res)
def reply(request): user, project = request.form['user'], request.form['project'] global message_count msg, question, image_path, tmp, page, answer_num, right_yn, collect_q, cq_num, cq, schedule_updated, trained_yn = [], request.form['msg'], '', request.form['tmp'], request.form['pge'], '', '', True, 0, [], 'N', True mdfc_rgsn_date = '' multiple_answer_num = request.form['multiple_answer_num'] message_count += 1 function_yn = 'N' user_ip = request.remote_addr param_holder = '' if multiple_answer_num != '': msg, tmp = faq_manager.get_answer_in_multiple(multiple_answer_num, question, user, project), '' multiple_answer_num = '' elif tmp != '': msg, tmp, function_nm, param_holder = function_adapter.continue_dialogue( user_ip, question, tmp) if function_nm == 'set_my_schedule()': schedule_updated = 'Y' else: param, replacedMsg = function_adapter.get_param_and_replaced_msg( question) is_fixed = fixed_question_processor.is_fixed_question(question) if is_fixed == False: _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, replacedMsg, collect_q, language) if answer_num == '': _, answer_num = run.run_chatbot(enc_vocab, rev_dec_vocab, replacedMsg + ' ', collect_q, language) if len(answer_num.split(";")) > 1: answer = '' message = faq_manager.get_reserve_question_list( question, answer_num, answer_num_and_rpsn_question) msg.append(message) else: answer, mdfc_rgsn_date = db_chat.get_answer_by_answer_num( user, project, answer_num) else: answer = fixed_question_processor.get_function_by_question( question) multiple_answer_num = '' if answer != '': if answer[:1] == '$': param[0]['function_nm'] = answer.replace('\n', '').split(" ")[1] msg, tmp, function_nm, param_holder = function_adapter.get_message_by_function( param, message_count, 'N') function_yn = 'Y' else: tmp = '' multiple_answer_num, multiple_answer = faq_manager.check_multiple_answer( answer_num, user, project) if multiple_answer_num != '': msg.append(multiple_answer) else: msg, right_yn, image_path, trained_yn = faq_manager.get_faq_answer( user, project, msg, answer_num, answer, question, message_count, mdfc_rgsn_date) db_chat.collect_question(user_ip, question, answer_num) cq = db_chat.get_same_category_question_list( user, project, answer_num) cq_num = len(cq) num = len(msg) res = { 'num': str(num), 'cq_num': str(cq_num), 'message_count': message_count, 'qst': question, 'ans_num': answer_num, 'image_path': str(image_path), 'right_yn': right_yn, 'temp': tmp, 'page': page, 'schedule_updated': schedule_updated, 'multiple_answer_num': multiple_answer_num } res['rpsn_question'] = '' res['function_yn'] = function_yn res['param_holder'] = param_holder if trained_yn == True: res['rpsn_question'] = answer_num_and_rpsn_question.get(answer_num, '') for i in range(num): res['text' + str(i + 1)] = msg[i] for i in range(cq_num): res['cq' + str(i + 1)] = cq[i] return jsonify(res)