def setup_args(parser=None): if parser is None: parser = ParlaiParser(True, True, 'Like interactive, but adds a safety filter') parser.add_argument('-d', '--display-examples', type='bool', default=False) parser.add_argument( '--display-prettify', type='bool', default=False, help='Set to use a prettytable when displaying ' 'examples with text candidates', ) parser.add_argument( '--display-add-fields', type=str, default='', help= 'Display these fields when verbose is off (e.g., "--display-add-fields label_candidates,beam_texts")', ) parser.add_argument( '-it', '--interactive-task', type='bool', default=True, help='Create interactive version of task', ) parser.set_defaults(interactive_mode=True, task='interactive') SafeLocalHumanAgent.add_cmdline_args(parser, partial_opt=None) return parser
def setup_args(parser=None): if parser is None: parser = ParlaiParser(True, True, 'Interactive chat with a model') parser.add_argument('-d', '--display-examples', type='bool', default=False) parser.add_argument( '--display-prettify', type='bool', default=False, help='Set to use a prettytable when displaying ' 'examples with text candidates', ) parser.add_argument( '--display-ignore-fields', type=str, default='label_candidates,text_candidates', help='Do not display these fields', ) parser.add_argument( '-it', '--interactive-task', type='bool', default=True, help='Create interactive version of task', ) parser.set_defaults(interactive_mode=True, task='interactive') SafeLocalHumanAgent.add_cmdline_args(parser) return parser
def interactive(opt, print_parser=None): if print_parser is not None: if print_parser is True and isinstance(opt, ParlaiParser): print_parser = opt elif print_parser is False: print_parser = None if isinstance(opt, ParlaiParser): print( '[ Deprecated Warning: interactive should be passed opt not Parser ]' ) opt = opt.parse_args() # Create model and assign it to the specified task agent = create_agent(opt, requireModelExists=True) if print_parser: # Show arguments after loading model print_parser.opt = agent.opt print_parser.print_args() human_agent = SafeLocalHumanAgent(opt) world = create_task(opt, [human_agent, agent]) # Show some example dialogs: while True: world.parley() if opt.get('display_examples'): print("---") print(world.display()) if world.epoch_done(): print("EPOCH DONE") break
def safe_interactive(opt, print_parser=None): if print_parser is not None: if print_parser is True and isinstance(opt, ParlaiParser): print_parser = opt elif print_parser is False: print_parser = None if isinstance(opt, ParlaiParser): print( '[ Deprecated Warning: interactive should be passed opt not Parser ]' ) opt = opt.parse_args() # Create model and assign it to the specified task agent = create_agent(opt, requireModelExists=True) if print_parser: # Show arguments after loading model print_parser.opt = agent.opt print_parser.print_args() human_agent = SafeLocalHumanAgent(opt) world = create_task(opt, [human_agent, agent]) # Interact until episode done while True: world.parley() bot_act = world.get_acts()[-1] if 'bot_offensive' in bot_act and bot_act['bot_offensive']: agent.reset() if opt.get('display_examples'): print('---') print(world.display()) if world.epoch_done(): print('EPOCH DONE') break
def setup_agent(): random.seed(42) parser = safe_interactive.setup_args() parser.prog = '' #parsed = parser.parse_args(print_args=False) parsed = { 'init_opt': None, 'show_advanced_args': False, 'task': 'blended_skill_talk', 'download_path': '/home/ubuntu/ParlAI/downloads', 'datatype': 'train', 'image_mode': 'raw', 'numthreads': 1, 'hide_labels': False, 'multitask_weights': [1], 'batchsize': 1, 'dynamic_batching': None, 'datapath': '/home/ubuntu/ParlAI/data', 'model': 'blender_90M', 'model_file': '/home/ubuntu/ParlAI/data/models/blender/blender_90M/model', 'init_model': None, 'dict_class': None, 'display_examples': False, 'display_prettify': False, 'display_ignore_fields': 'label_candidates,text_candidates', 'interactive_task': True, 'safety': 'all', 'local_human_candidates_file': None, 'single_turn': False, 'image_size': 256, 'image_cropsize': 224, 'interactive_mode': True, 'parlai_home': '/home/ubuntu/ParlAI', 'override': {}, 'starttime': 'May08_22-10', 'display_partner_persona': False } parsed.update({'model': 'blender_90M'}) parsed.update({'model_file': 'zoo:blender/blender_90M/model'}) parsed.update({'task': 'blended_skill_talk'}) parsed.update({'display_partner_persona': False}) # can do all the instructions in the function. issue is its interactive agent = create_agent(parsed, requireModelExists=True) if parser: # Show arguments after loading model parser.opt = agent.opt human_agent = SafeLocalHumanAgent(parsed) world = create_task(parsed, [human_agent, agent]) return world
def safe_interactive_custom(opt, print_parser=None): if print_parser is not None: if print_parser is True and isinstance(opt, ParlaiParser): print_parser = opt elif print_parser is False: print_parser = None if isinstance(opt, ParlaiParser): logging.error('interactive should be passed opt not Parser') opt = opt.parse_args() # Create model and assign it to the specified task agent = create_agent(opt, requireModelExists=True) if print_parser: # Show arguments after loading model print_parser.opt = agent.opt print_parser.print_args() human_agent = SafeLocalHumanAgent(opt) world = create_task(opt, [human_agent, agent]) return world
def setup_interactive(self): """ Build and parse CLI opts. """ self.SHARED['opt'] = self.opt self.SHARED['opt']['task'] = 'parlai.agents.local_human.local_human:LocalHumanAgent' # Create model and assign it to the specified task #import pdb; pdb.set_trace() if 'models' in self.opt: model_params = {} for model in self.opt['models']: model_opt = self.opt['models'][model] agent = create_agent(model_opt, requireModelExists=True) else: agent = create_agent(self.opt, requireModelExists=True) human_agent = SafeLocalHumanAgent(self.opt) self.SHARED['agent'] = agent self.SHARED['world'] = create_task(self.SHARED.get('opt'), [human_agent, self.SHARED['agent']])
def safe_interactive(opt): if isinstance(opt, ParlaiParser): logging.error('interactive should be passed opt not Parser') opt = opt.parse_args() # Create model and assign it to the specified task agent = create_agent(opt, requireModelExists=True) agent.opt.log() human_agent = SafeLocalHumanAgent(opt) world = create_task(opt, [human_agent, agent]) # Interact until episode done while True: world.parley() bot_act = world.get_acts()[-1] if 'bot_offensive' in bot_act and bot_act['bot_offensive']: agent.reset() if opt.get('display_examples'): print('---') print(world.display()) if world.epoch_done(): logging.info('epoch done') break
def safe_interactive(opt, print_parser=None): if print_parser is not None: if print_parser is True and isinstance(opt, ParlaiParser): print_parser = opt elif print_parser is False: print_parser = None if isinstance(opt, ParlaiParser): logging.error('interactive should be passed opt not Parser') opt = opt.parse_args() # Create model and assign it to the specified task agent = create_agent(opt, requireModelExists=True) if print_parser: # Show arguments after loading model print_parser.opt = agent.opt print_parser.print_args() human_agent = SafeLocalHumanAgent(opt) world = create_task(opt, [human_agent, agent]) # Interact until episode done # while True: # world.parley() # bot_act = world.get_acts()[-1] # if 'bot_offensive' in bot_act and bot_act['bot_offensive']: # agent.reset() # # if opt.get('display_examples'): # print('---') # print(world.display()) # if world.epoch_done(): # logging.info('epoch done') # break if not opt.get('chat_script'): '''for chateval script evaluation''' # Interact until episode done while True: world.parley() bot_act = world.get_acts()[-1] if 'bot_offensive' in bot_act and bot_act['bot_offensive']: agent.reset() if opt.get('display_examples'): print('---') print(world.display()) if world.epoch_done(): logging.info('epoch done') break # else: elif opt.get('chat_script') and opt.get('include_personas'): while True: # world.parley_script(opt.get('script_input_path'), opt.get('script_output_path'), opt.get('model-file')) # turn_available = [0, 2, 3] world.parley_persona_script(opt.get('script_input_path'), opt.get('script_output_path'), opt.get('model_file'), opt.get('chateval_multi'), opt.get('chateval_multi_num')) bot_act = world.get_acts()[-1] if 'bot_offensive' in bot_act and bot_act['bot_offensive']: agent.reset() if opt.get('display_examples'): print("---") print(world.display()) if world.epoch_done(): logging.info('epoch done') break else: while True: # world.parley_script(opt.get('script_input_path'), opt.get('script_output_path'), opt.get('model-file')) # turn_available = [0, 2, 3] world.parley_script(opt.get('script_input_path'), opt.get('script_output_path'), opt.get('model_file'), opt.get('chateval_multi'), opt.get('chateval_multi_num')) bot_act = world.get_acts()[-1] if 'bot_offensive' in bot_act and bot_act['bot_offensive']: agent.reset() if opt.get('display_examples'): print("---") print(world.display()) if world.epoch_done(): logging.info('epoch done') break
def setup_args(parser=None): if parser is None: parser = ParlaiParser(True, True, 'Interactive chat with a model') parser.add_argument('-d', '--display-examples', type='bool', default=False) parser.add_argument( '--display-prettify', type='bool', default=False, help='Set to use a prettytable when displaying ' 'examples with text candidates', ) parser.add_argument( '--display-ignore-fields', type=str, default='label_candidates,text_candidates', help='Do not display these fields', ) parser.add_argument( '-it', '--interactive-task', type='bool', default=True, help='Create interactive version of task', ) parser.add_argument( '-sc', '--script-chateval', type='bool', default=False, dest='chat_script', help='Chateval script read file' 'True: chateval evaluation, False: single-turn conversation with agent(original model)', ) parser.add_argument( '-scip', '--chateval-input-path', type=str, default=None, dest='script_input_path', help='Chateval script input path', ) parser.add_argument( '-scop', '--chateval-output-path', type=str, default=None, dest='script_output_path', help='Chateval result output path', ) parser.add_argument( '--chateval-multi-num', type=int, default=0, dest='chateval_multi_num', help='True is chateval multiturn setting, turn coverage count.', ) parser.add_argument( '--chateval-multi', type='bool', default=False, hidden=True, dest='chateval_multi', help='True is chateval multiturn setting, False just single turn.', ) parser.set_defaults(interactive_mode=True, task='interactive') SafeLocalHumanAgent.add_cmdline_args(parser) return parser