def chat_fun_urdu(n_query, model, chat_settings, chatlog_filepath): chk, response = wt.query_check(n_query) terminate_chat = False #Get the input and check if it is a question or a command, and execute if it is a command #question = input("You: ") question = n_query is_command, terminate_chat, reload_model = chat_command_handler.handle_command( question, model, chat_settings) if is_command: pass elif chk: return response else: question = ChatSettings.To_query(n_query) #If it is not a command (it is a question), pass it on to the chatbot model to get the answer question_with_history, answer = model.chat(question, chat_settings) #Print the answer or answer beams and log to chat log if chat_settings.show_question_context: print("Question with history (context): {0}".format( question_with_history)) if chat_settings.show_all_beams: for i in range(len(answer)): print("ChatBot (Beam {0}): {1}".format(i, answer[i])) else: n_answer = ChatSettings.To_answer(answer) print("ChatBot: {0}".format(n_answer)) print() return n_answer if chat_settings.inference_hparams.log_chat: chat_command_handler.append_to_chatlog(chatlog_filepath, question, answer)
def chat_fun(n_query): terminate_chat = False reload_model = False chk, response = wt.query_check(n_query) while not terminate_chat: #Create the model print() print("Initializing model..." if not reload_model else "Re-initializing model...") print() with ChatbotModel(mode="infer", model_hparams=chat_settings.model_hparams, input_vocabulary=input_vocabulary, output_vocabulary=output_vocabulary, model_dir=model_dir) as model: #Load the weights print() print("Loading model weights...") print() model.load(checkpoint) #Show the commands if not reload_model: #Uncomment the following line if you want to print commands. #chat_command_handler.print_commands() print('Model Reload!') while True: #Get the input and check if it is a question or a command, and execute if it is a command #question = input("You: ") question = n_query is_command, terminate_chat, reload_model = chat_command_handler.handle_command( question, model, chat_settings) if terminate_chat or reload_model: break elif is_command: continue elif chk: return response else: question = ChatSettings.To_query(n_query) #If it is not a command (it is a question), pass it on to the chatbot model to get the answer question_with_history, answer = model.chat( question, chat_settings) #Print the answer or answer beams and log to chat log if chat_settings.show_question_context: print("Question with history (context): {0}".format( question_with_history)) if chat_settings.show_all_beams: for i in range(len(answer)): print("ChatBot (Beam {0}): {1}".format( i, answer[i])) else: n_answer = ChatSettings.To_answer(answer) print("ChatBot: {0}".format(n_answer)) print() return n_answer if chat_settings.inference_hparams.log_chat: chat_command_handler.append_to_chatlog( chatlog_filepath, question, answer)