Exemple #1
0
def _test_core(stories: Optional[Text], agent: "Agent", output_directory: Text,
               **kwargs: Any) -> None:
    from rasa.core.test import test

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        test(stories, agent, out_directory=output_directory, **kwargs))
Exemple #2
0
def test_core(
    model: Optional[Text] = None,
    stories: Optional[Text] = None,
    output: Text = DEFAULT_RESULTS_PATH,
    additional_arguments: Optional[Dict] = None,
) -> None:
    """Tests a trained Core model against a set of test stories."""
    import rasa.model
    from rasa.shared.nlu.interpreter import RegexInterpreter
    from rasa.core.agent import Agent

    if additional_arguments is None:
        additional_arguments = {}

    if output:
        rasa.shared.utils.io.create_directory(output)

    try:
        unpacked_model = rasa.model.get_model(model)
    except ModelNotFound:
        rasa.shared.utils.cli.print_error(
            "Unable to test: could not find a model. Use 'rasa train' to train a "
            "Rasa model and provide it via the '--model' argument.")
        return

    _agent = Agent.load(unpacked_model)

    if _agent.policy_ensemble is None:
        rasa.shared.utils.cli.print_error(
            "Unable to test: could not find a Core model. Use 'rasa train' to train a "
            "Rasa model and provide it via the '--model' argument.")

    if isinstance(_agent.interpreter, RegexInterpreter):
        rasa.shared.utils.cli.print_warning(
            "No NLU model found. Using default 'RegexInterpreter' for end-to-end "
            "evaluation. If you added actual user messages to your test stories "
            "this will likely lead to the tests failing. In that case, you need "
            "to train a NLU model first, e.g. using `rasa train`.")

    from rasa.core.test import test

    kwargs = rasa.shared.utils.common.minimal_kwargs(additional_arguments,
                                                     test,
                                                     ["stories", "agent"])

    rasa.utils.common.run_in_loop(
        test(stories, _agent, out_directory=output, **kwargs))