def test_training_script(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, policy_config='data/test_config/max_hist_config.yml', interpreter=RegexInterpreter(), kwargs={}) assert True
def test_remote_example(): from rasa_core import train, run train.train_dialogue_model("examples/remotebot/concert_domain_remote.yml", "examples/remotebot/data/stories.md", "examples/remotebot/models/dialogue", False, None, {}) agent = run.main("examples/remotebot/models/dialogue") response = agent.start_message_handling("_search_venues") assert response.get("next_action") == 'search_venues' assert response.get("tracker") == { 'slots': { 'concerts': None, 'venues': None }, 'sender_id': 'default', 'paused': False, 'latest_message': { 'text': '_search_venues', 'intent_ranking': [{ 'confidence': 1.0, 'name': 'search_venues' }], 'intent': { 'confidence': 1.0, 'name': 'search_venues' }, 'entities': [] } } next_response = agent.continue_message_handling("default", "search_venues", []) assert next_response.get("next_action") == "action_listen"
def test_training_script(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, use_online_learning=False, nlu_model_path=None, kwargs={}) assert True
def test_training_script(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, interpreter=RegexInterpreter(), kwargs={}) assert True
def test_training_script_with_restart_stories(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, "data/test_stories/stories_restart.md", tmpdir.strpath, interpreter=RegexInterpreter(), kwargs={}) assert True
def test_training_script(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, use_online_learning=False, nlu_model_path=None, kwargs={})
def trained_moodbot_path(): train.train_dialogue_model(domain_file="examples/moodbot/domain.yml", stories_file="examples/moodbot/data/stories.md", output_path=MOODBOT_MODEL_PATH, interpreter=RegexInterpreter(), max_history=None, kwargs=None) return MOODBOT_MODEL_PATH
def trained_moodbot_path(): train.train_dialogue_model(domain_file="examples/moodbot/domain.yml", stories_file="examples/moodbot/data/stories.md", output_path=MOODBOT_MODEL_PATH, interpreter=RegexInterpreter(), policy_config='rasa_core/default_config.yml', kwargs=None) return MOODBOT_MODEL_PATH
def test_remote_training(tmpdir): train_dialogue_model("examples/remote/concert_domain_remote.yml", "examples/remote/data/stories.md", tmpdir.strpath, {}) agent = Agent.load(tmpdir.strpath) assert agent.domain._factory_name == "remote" action_types = [type(a) for a in agent.domain.actions] assert action_types[:3] == [ActionListen, ActionRestart, RemoteAction]
def test_training_script_with_max_history_set(tmpdir): max_history = 3 train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, nlu_model_path=None, max_history=max_history, kwargs={}) agent = Agent.load(tmpdir.strpath) for policy in agent.policy_ensemble.policies: if hasattr(policy.featurizer, 'max_history'): assert policy.featurizer.max_history == max_history
def test_training_script_without_max_history_set(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, interpreter=RegexInterpreter(), max_history=None, kwargs={}) agent = Agent.load(tmpdir.strpath) for policy in agent.policy_ensemble.policies: if hasattr(policy.featurizer, 'max_history'): assert policy.featurizer.max_history == \ policy.featurizer.MAX_HISTORY_DEFAULT
def train_dialogue(domain_file="config/domain.yml", model_path="models/dialogue", stories_file="config/stories.md", policy_config="config/policy_config.yml"): #endpoints_file="config/endpoints.yml"): train_dialogue_model(domain_file=domain_file, stories_file=stories_file, output_path=model_path, policy_config=policy_config, kwargs=_additional_arguments())
def trained_moodbot_path(): model_path = "examples/moodbot/models/dialogue" train.train_dialogue_model( domain_file="examples/moodbot/domain.yml", stories_file="examples/moodbot/data/stories.md", output_path=model_path, use_online_learning=False, nlu_model_path=None, max_history=None, kwargs=None ) return model_path
def trained_moodbot_path(): model_path = "examples/moodbot/models/dialogue" train.train_dialogue_model( domain_file="examples/moodbot/domain.yml", stories_file="examples/moodbot/data/stories.md", output_path=model_path, use_online_learning=False, nlu_model_path=None, max_history=None, kwargs=None ) return model_path
def test_training_script_without_max_history_set(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, use_online_learning=False, nlu_model_path=None, max_history=None, kwargs={}) agent = Agent.load(tmpdir.strpath) for policy in agent.policy_ensemble.policies: if hasattr(policy.featurizer, 'max_history'): assert policy.featurizer.max_history == \ policy.featurizer.MAX_HISTORY_DEFAULT
def test_training_script_with_max_history_set(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, interpreter=RegexInterpreter(), policy_config='data/test_config/max_hist_config.yml', kwargs={}) agent = Agent.load(tmpdir.strpath) for policy in agent.policy_ensemble.policies: if hasattr(policy.featurizer, 'max_history'): if type(policy) == FormPolicy: assert policy.featurizer.max_history == 2 else: assert policy.featurizer.max_history == 5
def test_remote_example(): from rasa_core import train, run from rasa_core.events import SlotSet train.train_dialogue_model( domain_file="examples/remotebot/concert_domain_remote.yml", stories_file="examples/remotebot/data/stories.md", output_path="examples/remotebot/models/dialogue", use_online_learning=False, nlu_model_path=None, max_history=None, kwargs=None) agent = run.main("examples/remotebot/models/dialogue") response = agent.start_message_handling("/search_venues") assert response.get("next_action") == 'search_venues' reference = { 'slots': { 'concerts': None, 'venues': None }, 'events': None, 'sender_id': 'default', 'paused': False, 'latest_event_time': 1513023382.101372, 'latest_message': { 'text': '/search_venues', 'intent_ranking': [{ 'confidence': 1.0, 'name': 'search_venues' }], 'intent': { 'confidence': 1.0, 'name': 'search_venues' }, 'entities': [] } } result = response.get("tracker") assert reference.keys() == result.keys() del reference['latest_event_time'] del result['latest_event_time'] assert reference == result venues = [{"name": "Big Arena", "reviews": 4.5}] next_response = agent.continue_message_handling( "default", "search_venues", [SlotSet("venues", venues)]) assert next_response.get("next_action") == "action_listen"
def test_remote_training(tmpdir): train_dialogue_model("examples/remotebot/concert_domain_remote.yml", "examples/remotebot/data/stories.md", tmpdir.strpath, use_online_learning=False, nlu_model_path=None, kwargs={}) agent = Agent.load(tmpdir.strpath) assert agent.domain._factory_name == "remote" action_types = [type(a) for a in agent.domain.actions] assert action_types[:4] == [ActionListen, ActionRestart, ActionDefaultFallback, RemoteAction]
def test_remote_training(tmpdir): train_dialogue_model("examples/remotebot/concert_domain_remote.yml", "examples/remotebot/data/stories.md", tmpdir.strpath, use_online_learning=False, nlu_model_path=None, kwargs={}) agent = Agent.load(tmpdir.strpath) assert agent.domain._factory_name == "remote" action_types = [type(a) for a in agent.domain.actions] assert action_types[:4] == [ ActionListen, ActionRestart, ActionDefaultFallback, RemoteAction ]
def test_moodbot_example(): from rasa_core import train, run train.train_dialogue_model("examples/moodbot/domain.yml", "examples/moodbot/data/stories.md", "examples/moodbot/models/dialogue", False, None, {}) agent = run.main("examples/moodbot/models/dialogue") responses = agent.handle_message("_greet") assert responses[0] == 'Hey! How are you?' responses.extend(agent.handle_message("_mood_unhappy")) assert responses[-1] in {"Did that help you?"} # (there is a 'I am on it' message in the middle we are not checking) assert len(responses) == 6
def train_agent(): return train.train_dialogue_model(domain_file="domain.yml", stories_file="data/stories.md", output_path="models/dialogue", kwargs={"batch_size": 50, "epochs": 200, "max_training_samples": 300 })
def train_dialogue(self, domain_file='domain.yml', stories_file='data/stories.md', model_path='model/dialogue', policy_config='config/config.yml'): return train.train_dialogue_model(domain_file=domain_file, stories_file=stories_file, output_path=model_path, policy_config=policy_config)
def train_dialogue(domain_file, model_path, training_folder, policy_config): return train.train_dialogue_model(domain_file=domain_file, stories_file=training_folder, output_path=model_path, policy_config=policy_config, kwargs={ 'augmentation_factor': 20, 'validation_split': 0.2, })
def test_formbot_example(): sys.path.append("examples/formbot/") p = "examples/formbot/" stories = os.path.join(p, "data", "stories.md") endpoint = EndpointConfig("https://abc.defg/webhooks/actions") endpoints = AvailableEndpoints(action=endpoint) agent = train_dialogue_model(os.path.join(p, "domain.yml"), stories, os.path.join(p, "models", "dialogue"), endpoints=endpoints, policy_config="rasa_core/default_config.yml") response = { 'events': [{ 'event': 'form', 'name': 'restaurant_form', 'timestamp': None }, { 'event': 'slot', 'timestamp': None, 'name': 'requested_slot', 'value': 'cuisine' }], 'responses': [{ 'template': 'utter_ask_cuisine' }] } httpretty.register_uri(httpretty.POST, 'https://abc.defg/webhooks/actions', body=json.dumps(response)) httpretty.enable() responses = agent.handle_text("/request_restaurant") httpretty.disable() assert responses[0]['text'] == 'what cuisine?' response = { "error": "Failed to validate slot cuisine with action restaurant_form", "action_name": "restaurant_form" } httpretty.register_uri(httpretty.POST, 'https://abc.defg/webhooks/actions', status=400, body=json.dumps(response)) httpretty.enable() responses = agent.handle_text("/chitchat") httpretty.disable() assert responses[0]['text'] == 'chitchat'
def train_agent(): return train.train_dialogue_model(domain_file="domain.yml", stories_file="data/stories.md", output_path="models/dialogue", endpoints="endpoints.yml", max_history=2, kwargs={"batch_size": 50, "epochs": 200, "max_training_samples": 300 })
def train_agent(interpreter): return train.train_dialogue_model(domain_file="horoscope_domain.yml", stories_file="data/stories.md", output_path="models/dialog", nlu_model_path=interpreter, endpoints="endpoints.yml", max_history=2, kwargs={"batch_size": 50, "epochs": 200, "max_training_samples": 300 })
def test_remote_example(): from rasa_core import train, run from rasa_core.events import SlotSet train.train_dialogue_model( domain_file="examples/remotebot/concert_domain_remote.yml", stories_file="examples/remotebot/data/stories.md", output_path="examples/remotebot/models/dialogue", use_online_learning=False, nlu_model_path=None, max_history=None, kwargs=None ) agent = run.main("examples/remotebot/models/dialogue") response = agent.start_message_handling("/search_venues") assert response.get("next_action") == 'search_venues' reference = { 'slots': {'concerts': None, 'venues': None}, 'events': None, 'sender_id': 'default', 'paused': False, 'latest_event_time': 1513023382.101372, 'latest_message': { 'text': '/search_venues', 'intent_ranking': [{'confidence': 1.0, 'name': 'search_venues'}], 'intent': {'confidence': 1.0, 'name': 'search_venues'}, 'entities': []}} result = response.get("tracker") assert reference.keys() == result.keys() del reference['latest_event_time'] del result['latest_event_time'] assert reference == result venues = [{"name": "Big Arena", "reviews": 4.5}] next_response = agent.continue_message_handling( "default", "search_venues", [SlotSet("venues", venues)] ) assert next_response.get("next_action") == "action_listen"
def train_dialogue(domain_file='domain.yml', stories_file='data/stories.md', model_path='models/dialogue', policy_config='policy_config.yml'): return train.train_dialogue_model(domain_file=domain_file, stories_file=stories_file, output_path=model_path, policy_config=policy_config, kwargs={ 'augmentation_factor': 50, 'validation_split': 0.2 })
def run_online(domain_file="config/domain.yml", stories_file="config/stories.md", output_path="models/dialogue", max_history=3, kwargs={"batch_size": 50, "epochs": 800, "max_training_samples": 300}): interpreter = RasaNLUInterpreter("models/ticket/nlu_bot") agent = train.train_dialogue_model(domain_file=domain_file, interpreter=interpreter, stories_file=stories_file, output_path=output_path, max_history=max_history, endpoints=AvailableEndpoints.read_endpoints("config/endpoints.yml"), kwargs=kwargs) online.run_online_learning(agent)
def test_random_seed(tmpdir, config_file): # set random seed in config file to # generate a reproducible training result agent_1 = train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath + "1", interpreter=RegexInterpreter(), policy_config=config_file, kwargs={}) agent_2 = train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath + "2", interpreter=RegexInterpreter(), policy_config=config_file, kwargs={}) processor_1 = agent_1.create_processor() processor_2 = agent_2.create_processor() probs_1 = processor_1.predict_next("1") probs_2 = processor_2.predict_next("2") assert probs_1["confidence"] == probs_2["confidence"]
def test_formbot_example(): sys.path.append("examples/formbot/") p = "examples/formbot/" stories = os.path.join(p, "data", "stories.md") endpoint = EndpointConfig("http://localhost:5055/webhook") endpoints = AvailableEndpoints(action=endpoint) agent = train_dialogue_model(os.path.join(p, "domain.yml"), stories, os.path.join(p, "models", "dialogue"), endpoints=endpoints, policy_config="rasa_core/default_config.yml") # response = { # 'events': [ # {'event': 'form', 'name': 'restaurant_form', 'timestamp': None}, # {'event': 'slot', 'timestamp': None, # 'name': 'requested_slot', 'value': 'cuisine'} # ], # 'responses': [ # {'template': 'utter_ask_cuisine'} # ] # } print(type(agent.policy_ensemble)) responses = agent.handle_text("/request_restaurant") # assert responses[0]['text'] == 'what cuisine?' print(responses) # response = { # "error": "Failed to validate slot cuisine with action restaurant_form", # "action_name": "restaurant_form" # } responses = agent.handle_text("/chitchat") # assert responses[0]['text'] == 'chitchat' print(responses[0])
def test_training_script(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, {})
def train_dialog(): conf = Config() train_dialogue_model(conf.get_value('domain-file'), conf.get_value('stories-file'), conf.get_value('dialog-model-path'))
def test_training_script(tmpdir): train_dialogue_model(DEFAULT_DOMAIN_PATH, DEFAULT_STORIES_FILE, tmpdir.strpath, nlu_model_path=None, kwargs={}) assert True
def trained_moodbot_path(): model_path = "examples/moodbot/models/dialogue" train.train_dialogue_model("examples/moodbot/domain.yml", "examples/moodbot/data/stories.md", model_path, False, None, {}) return model_path
def train_dialog(): train_dialogue_model(CONF.get_value('domain-file'), CONF.get_value('stories-file'), CONF.get_value('dialog-model-path'))