Ejemplo n.º 1
0
def _core_service(args: argparse.Namespace,
                  endpoints: "AvailableEndpoints" = None):
    """Starts the Rasa Core application."""
    from rasa.core.run import serve_application
    from rasa.nlu.utils import configure_colored_logging

    configure_colored_logging(args.loglevel)
    logging.getLogger("apscheduler.executors.default").setLevel(
        logging.WARNING)

    args.credentials = get_validated_path(args.credentials, "credentials",
                                          DEFAULT_CREDENTIALS_PATH, True)

    if endpoints is None:
        args.endpoints = get_validated_path(args.endpoints, "endpoints",
                                            DEFAULT_ENDPOINTS_PATH, True)
        from rasa.core.utils import AvailableEndpoints

        endpoints = AvailableEndpoints.read_endpoints(args.endpoints)

    serve_application(
        endpoints=endpoints,
        port=args.port,
        credentials=args.credentials,
        cors=args.cors,
        auth_token=args.auth_token,
        enable_api=True,
        jwt_secret=args.jwt_secret,
        jwt_method=args.jwt_method,
    )
Ejemplo n.º 2
0
def main(args):
    utils.configure_colored_logging(args.loglevel)
    pre_load = args.pre_load

    _endpoints = read_endpoints(args.endpoints)

    router = DataRouter(args.path,
                        args.max_training_processes,
                        args.response_log,
                        args.emulate,
                        args.storage,
                        model_server=_endpoints.model,
                        wait_time_between_pulls=args.wait_time_between_pulls)
    if pre_load:
        logger.debug('Preloading....')
        if 'all' in pre_load:
            pre_load = router.project_store.keys()
        router._pre_load(pre_load)

    rasa = RasaNLU(router,
                   args.loglevel,
                   args.write,
                   args.num_threads,
                   get_token(cmdline_args.token),
                   args.cors,
                   default_config_path=args.config)

    logger.info('Started http server on port %s' % args.port)
    rasa.app.run('0.0.0.0', args.port)
Ejemplo n.º 3
0
 def _configure_logging(loglevel, logfile):
     if logfile is None:
         utils.configure_colored_logging(loglevel)
     else:
         logging.basicConfig(filename=logfile,
                             level=loglevel)
     logging.captureWarnings(True)
Ejemplo n.º 4
0
Archivo: x.py Proyecto: jayceyxc/rasa
def rasa_x(args: argparse.Namespace):
    from rasa.cli.utils import print_success, print_error, signal_handler
    from rasa.core.utils import configure_file_logging
    from rasa.utils.io import configure_colored_logging

    signal.signal(signal.SIGINT, signal_handler)

    logging.getLogger("werkzeug").setLevel(logging.WARNING)
    logging.getLogger("engineio").setLevel(logging.WARNING)
    logging.getLogger("pika").setLevel(logging.WARNING)
    logging.getLogger("socketio").setLevel(logging.ERROR)

    if not args.loglevel == logging.DEBUG:
        logging.getLogger().setLevel(logging.WARNING)
        logging.getLogger("py.warnings").setLevel(logging.ERROR)
        logging.getLogger("apscheduler").setLevel(logging.ERROR)
        logging.getLogger("rasa").setLevel(logging.WARNING)
        logging.getLogger("sanic.root").setLevel(logging.ERROR)

    log_level = args.loglevel or DEFAULT_LOG_LEVEL
    configure_colored_logging(log_level)
    configure_file_logging(log_level, args.log_file)

    metrics = is_metrics_collection_enabled(args)

    if args.production:
        print_success("Starting Rasa X in production mode... 🚀")
        _core_service(args)
    else:
        print_success("Starting Rasa X in local mode... 🚀")
        if not is_rasa_x_installed():
            print_error(
                "Rasa X is not installed. The `rasa x` "
                "command requires an installation of Rasa X."
            )
            sys.exit(1)

        # noinspection PyUnresolvedReferences
        from rasax.community.api.local import main_local

        start_event_service()

        rasa_x_token = generate_rasa_x_token()

        start_core_for_local_platform(args, rasa_x_token=rasa_x_token)

        main_local(
            args.project_path, args.data_path, token=rasa_x_token, metrics=metrics
        )
Ejemplo n.º 5
0
def main():
    parser = create_argument_parser()
    cmdline_args = parser.parse_args()
    utils.configure_colored_logging(cmdline_args.loglevel)

    if cmdline_args.mode == "crossvalidation":

        # TODO: move parsing into sub parser
        # manual check argument dependency
        if cmdline_args.model is not None:
            parser.error("Crossvalidation will train a new model "
                         "- do not specify external model.")

        if cmdline_args.config is None:
            parser.error("Crossvalidation will train a new model "
                         "you need to specify a model configuration.")

        nlu_config = config.load(cmdline_args.config)
        data = training_data.load_data(cmdline_args.data)
        data = drop_intents_below_freq(data, cutoff=5)
        results, entity_results = cross_validate(data, int(cmdline_args.folds),
                                                 nlu_config)
        logger.info("CV evaluation (n={})".format(cmdline_args.folds))

        if any(results):
            logger.info("Intent evaluation results")
            return_results(results.train, "train")
            return_results(results.test, "test")
        if any(entity_results):
            logger.info("Entity evaluation results")
            return_entity_results(entity_results.train, "train")
            return_entity_results(entity_results.test, "test")

    elif cmdline_args.mode == "evaluation":
        run_evaluation(
            cmdline_args.data,
            cmdline_args.model,
            cmdline_args.report,
            cmdline_args.successes,
            cmdline_args.errors,
            cmdline_args.confmat,
            cmdline_args.histogram,
        )

    logger.info("Finished evaluation")
Ejemplo n.º 6
0
def _rasa_service(args: argparse.Namespace,
                  endpoints: "AvailableEndpoints",
                  rasa_x_url=None):
    """Starts the Rasa application."""
    from rasa.core.run import serve_application
    from rasa.nlu.utils import configure_colored_logging

    configure_colored_logging(args.loglevel)
    logging.getLogger("apscheduler.executors.default").setLevel(
        logging.WARNING)

    credentials_path = _prepare_credentials_for_rasa_x(args.credentials,
                                                       rasa_x_url=rasa_x_url)

    serve_application(
        endpoints=endpoints,
        port=args.port,
        credentials=credentials_path,
        cors=args.cors,
        auth_token=args.auth_token,
        enable_api=True,
        jwt_secret=args.jwt_secret,
        jwt_method=args.jwt_method,
    )
Ejemplo n.º 7
0
    if path:
        persisted_path = trainer.persist(path,
                                         persistor,
                                         project,
                                         fixed_model_name)
    else:
        persisted_path = None

    return trainer, interpreter, persisted_path


if __name__ == '__main__':
    cmdline_args = create_argument_parser().parse_args()

    utils.configure_colored_logging(cmdline_args.loglevel)

    if cmdline_args.url:
        data_endpoint = EndpointConfig(cmdline_args.url)
    else:
        data_endpoint = read_endpoints(cmdline_args.endpoints).data

    train(cmdline_args.config,
          cmdline_args.data,
          cmdline_args.path,
          cmdline_args.project,
          cmdline_args.fixed_model_name,
          cmdline_args.storage,
          training_data_endpoint=data_endpoint,
          num_threads=cmdline_args.num_threads)
    logger.info("Finished training")