def init_chatbot(): if 'bot' not in flask_app.config: logging.info( 'init_chatbot: profile_path="%s" models_folder="%s" data_folder="%s" chitchat_url="%s"', profile_path, models_folder, data_folder, chitchat_url) if chitchat_url: rugpt_chitchat_config = ChitchatConfig() rugpt_chitchat_config.service_endpoint = chitchat_url # rugpt_chitchat_config.temperature = 0.9 rugpt_chitchat_config.num_return_sequences = 2 logging.info('Chit-chat service to use: %s', str(rugpt_chitchat_config)) else: rugpt_chitchat_config = None logging.info('No chit-chat service!') bot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, debugging=True, chitchat_config=rugpt_chitchat_config) #def on_order(order_anchor_str, bot, session): # bot.say(session, 'Выполняю команду "{}"'.format(order_anchor_str)) #bot.on_process_order = on_order flask_app.config['bot'] = bot logging.info('init_chatbot complete')
def init_chatbot(): if 'bot' not in flask_app.config: logging.info('init_chatbot: models_folder="%s"', models_folder) bot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, debugging=True) def on_order(order_anchor_str, bot, session): bot.say(session, 'Выполняю команду "{}"'.format(order_anchor_str)) bot.on_process_order = on_order flask_app.config['bot'] = bot logging.info('init_chatbot complete')
profile_path = os.path.expanduser(args.profile) models_folder = os.path.expanduser(args.models_folder) data_folder = os.path.expanduser(args.data_folder) w2v_folder = os.path.expanduser(args.w2v_folder) tmp_folder = os.path.expanduser(args.tmp_folder) #logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) init_trainer_logging(os.path.join(tmp_folder, 'telegram_bot.log'), True) telegram_token = args.token if len(telegram_token) == 0: telegram_token = input('Enter Telegram token:> ').strip() tg_bot = telegram.Bot(token=telegram_token) logging.info('Telegram bot: %s', tg_bot.getMe()) logging.debug('Bot loading...') chatbot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, True, bot_id='telegram_bot') updater = Updater(token=telegram_token) dispatcher = updater.dispatcher start_handler = CommandHandler('start', start) dispatcher.add_handler(start_handler) echo_handler = MessageHandler(Filters.text, echo) dispatcher.add_handler(echo_handler) logging.info('Start polling messages for bot {}...'.format(tg_bot.getMe())) updater.start_polling()
tg_bot = telegram.Bot(token=telegram_token) logging.info('Telegram bot: %s', tg_bot.getMe()) if args.chitchat_url: rugpt_chitchat_config = ChitchatConfig() rugpt_chitchat_config.service_endpoint = args.chitchat_url # rugpt_chitchat_config.temperature = 0.9 rugpt_chitchat_config.num_return_sequences = 2 else: rugpt_chitchat_config = None logging.debug('Bot loading...') chatbot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, True, bot_id='telegram_bot', chitchat_config=rugpt_chitchat_config) updater = Updater(token=telegram_token) dispatcher = updater.dispatcher start_handler = CommandHandler('start', start) dispatcher.add_handler(start_handler) echo_handler = MessageHandler(Filters.text, echo) dispatcher.add_handler(echo_handler) logging.info('Start polling messages for bot {}...'.format(tg_bot.getMe())) updater.start_polling()
tmp_folder = os.path.expanduser(args.tmp_folder) init_trainer_logging(os.path.join(tmp_folder, 'console_chatbot.log'), args.debugging) if args.chitchat_url: rugpt_chitchat_config = ChitchatConfig() rugpt_chitchat_config.service_endpoint = args.chitchat_url # rugpt_chitchat_config.temperature = 0.9 rugpt_chitchat_config.num_return_sequences = 2 logging.info('Chit-chat service to use: %s', str(rugpt_chitchat_config)) else: rugpt_chitchat_config = None logging.info('No chit-chat service!') logging.debug('Bot loading...') bot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, args.debugging, chitchat_config=rugpt_chitchat_config) # Выполняем привязку обработчиков bot.on_process_order = on_order bot.add_event_handler(u'weather_forecast', on_weather_forecast) bot.add_event_handler(u'check_emails', on_check_emails) bot.add_event_handler(u'alarm_clock', on_alarm_clock) bot.add_event_handler(u'buy_pizza', on_buy_pizza) if args.greeting: bot.start_conversation(user_id) flush_logging() print_tech_banner() while True:
parser.add_argument('--models_folder', type=str, default='../../tmp', help='path to folder with pretrained models') parser.add_argument('--tmp_folder', type=str, default='../../tmp', help='path to folder for logfile etc') parser.add_argument('--debugging', action='store_true') parser.add_argument('--chitchat_url', type=str) args = parser.parse_args() profile_path = os.path.expanduser(args.profile) models_folder = os.path.expanduser(args.models_folder) data_folder = os.path.expanduser(args.data_folder) w2v_folder = os.path.expanduser(args.w2v_folder) tmp_folder = os.path.expanduser(args.tmp_folder) init_trainer_logging(os.path.join(tmp_folder, 'console_chatbot.log'), args.debugging) logging.debug('Bot loading...') bot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, args.debugging, chitchat_url=args.chitchat_url) # Выполняем привязку обработчиков bot.on_process_order = on_order bot.add_event_handler(u'weather_forecast', on_weather_forecast) bot.add_event_handler(u'check_emails', on_check_emails) bot.add_event_handler(u'alarm_clock', on_alarm_clock) bot.add_event_handler(u'buy_pizza', on_buy_pizza) bot.start_conversation(user_id) flush_logging() print_tech_banner() while True: print('\n')
default='../../tmp', help='path to folder for logfile etc') parser.add_argument('--debugging', action='store_true') args = parser.parse_args() profile_path = os.path.expanduser(args.profile) models_folder = os.path.expanduser(args.models_folder) data_folder = os.path.expanduser(args.data_folder) w2v_folder = os.path.expanduser(args.w2v_folder) tmp_folder = os.path.expanduser(args.tmp_folder) init_trainer_logging(os.path.join(tmp_folder, 'console_chatbot.log'), args.debugging) logging.debug('Bot loading...') bot = create_chatbot(profile_path, models_folder, w2v_folder, data_folder, args.debugging) # Выполняем привязку обработчиков bot.on_process_order = on_order bot.add_event_handler(u'weather_forecast', on_weather_forecast) bot.add_event_handler(u'check_emails', on_check_emails) bot.add_event_handler(u'alarm_clock', on_alarm_clock) bot.add_event_handler(u'buy_pizza', on_buy_pizza) bot.start_conversation(user_id) flush_logging() print_tech_banner() while True: print('\n')