示例#1
0
def main() -> None:
    # Running as standalone python application
    import os
    import sys

    parse_last_positional_argument_as_model_path()
    arg_parser = create_argument_parser()
    cmdline_arguments = arg_parser.parse_args()

    log_level = (cmdline_arguments.loglevel
                 if hasattr(cmdline_arguments, "loglevel") else None)
    set_log_level(log_level)

    # insert current path in syspath so custom modules are found
    sys.path.insert(1, os.getcwd())

    if hasattr(cmdline_arguments, "func"):
        rasa.utils.io.configure_colored_logging(log_level)
        cmdline_arguments.func(cmdline_arguments)
    elif hasattr(cmdline_arguments, "version"):
        print_version()
    else:
        # user has not provided a subcommand, let's print the help
        logger.error("No command specified.")
        arg_parser.print_help()
        exit(1)
示例#2
0
文件: agent.py 项目: zeroesones/rasa
async def _pull_model_and_fingerprint(
        model_server: EndpointConfig,
        fingerprint: Optional[Text]) -> Optional[Tuple[Text, Text]]:
    """Queries the model server.

    Returns the temporary model directory and value of the response's <ETag> header
    which contains the model hash. Returns `None` if no new model is found.
    """

    headers = {"If-None-Match": fingerprint}

    logger.debug("Requesting model from server {}...".format(model_server.url))

    async with model_server.session() as session:
        try:
            set_log_level()
            params = model_server.combine_parameters()
            async with session.request(
                    "GET",
                    model_server.url,
                    timeout=DEFAULT_REQUEST_TIMEOUT,
                    headers=headers,
                    params=params,
            ) as resp:

                if resp.status in [204, 304]:
                    logger.debug("Model server returned {} status code, "
                                 "indicating that no new model is available. "
                                 "Current fingerprint: {}"
                                 "".format(resp.status, fingerprint))
                    return None
                elif resp.status == 404:
                    logger.debug(
                        "Model server could not find a model at the requested "
                        "endpoint '{}'. It's possible that no model has been "
                        "trained, or that the requested tag hasn't been "
                        "assigned.".format(model_server.url))
                    return None
                elif resp.status != 200:
                    logger.debug(
                        "Tried to fetch model from server, but server response "
                        "status code is {}. We'll retry later..."
                        "".format(resp.status))
                    return None

                model_directory = tempfile.mkdtemp()
                rasa.utils.io.unarchive(await resp.read(), model_directory)
                logger.debug("Unzipped model to '{}'".format(
                    os.path.abspath(model_directory)))

                # get the new fingerprint
                new_fingerprint = resp.headers.get("ETag")
                # return new tmp model directory and new fingerprint
                return model_directory, new_fingerprint

        except aiohttp.ClientError as e:
            logger.debug("Tried to fetch model from server, but "
                         "couldn't reach server. We'll retry later... "
                         "Error: {}.".format(e))
            return None
示例#3
0
async def load_from_remote(server: EndpointConfig,
                           name: Text,
                           temp_file=True) -> Union[Text, Dict]:
    """Returns and object or a file from an endpoint
    """

    logger.debug("Requesting {} from server {}...".format(name, server.url))

    async with server.session() as session:
        try:
            set_log_level()
            params = server.combine_parameters()
            async with session.request(
                    "GET",
                    server.url,
                    timeout=DEFAULT_REQUEST_TIMEOUT,
                    params=params,
            ) as resp:

                if resp.status in [204, 304]:
                    logger.debug(
                        "Model server returned {} status code, indicating "
                        "that no new {} are available.".format(
                            resp.status, name))
                    return None
                elif resp.status == 404:
                    logger.warning(
                        "Tried to fetch {} from server but got a 404 response".
                        format(name))
                    raise requests.exceptions.InvalidURL(server.url)
                elif resp.status != 200:
                    logger.warning(
                        "Tried to fetch {} from server, but server response "
                        "status code is {}."
                        "".format(name, resp.status))
                    raise requests.exceptions.InvalidURL(server.url)

                if temp_file is True:
                    with tempfile.NamedTemporaryFile(mode='w',
                                                     delete=False) as yamlfile:
                        yaml.dump(await resp.json(), yamlfile)
                    return yamlfile.name
                else:
                    return await resp.json()

        except aiohttp.ClientError as e:
            logger.warning(
                "Tried to fetch rules from server, but couldn't reach "
                "server. We'll retry later... Error: {}."
                "".format(e))
            raise requests.exceptions.InvalidURL(server.url)
示例#4
0
def main(argv):
    set_log_level(None)
    model, train_data, test_data, config, run_name, original_config = initialize_values(
        argv)
    result_of_run = {}
    result_of_run['name'] = run_name
    result_of_run['importer'] = get_importer(original_config)
    result_of_run['policy'] = get_policies(config)
    loop = asyncio.get_event_loop()
    result_of_run['test'] = loop.run_until_complete(
        test_core(model=model, stories=test_data, output=model))
    result_of_run['train'] = loop.run_until_complete(
        test_core(model=model, stories=train_data))
    with open(model + '/test_run.pkl', 'wb') as f:
        pickle.dump(result_of_run, f)
示例#5
0
文件: x.py 项目: whitewolfkings/rasa
def _configure_logging(args):
    from rasa.core.utils import configure_file_logging
    from rasa.utils.common import set_log_level

    log_level = args.loglevel or DEFAULT_LOG_LEVEL_RASA_X

    if isinstance(log_level, str):
        log_level = logging.getLevelName(log_level)

    set_log_level(log_level)
    configure_file_logging(log_level, args.log_file)

    logging.basicConfig(level=log_level)

    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 log_level == logging.DEBUG:
        logging.getLogger().setLevel(logging.WARNING)
        logging.getLogger("py.warnings").setLevel(logging.ERROR)
示例#6
0
def main() -> None:
    # Running as standalone python application

    parse_last_positional_argument_as_model_path()
    arg_parser = create_argument_parser()
    cmdline_arguments = arg_parser.parse_args()

    log_level = (cmdline_arguments.loglevel
                 if hasattr(cmdline_arguments, "loglevel") else None)
    set_log_level(log_level)

    tf_env.setup_tf_environment()

    # insert current path in syspath so custom modules are found
    sys.path.insert(1, os.getcwd())

    try:
        if hasattr(cmdline_arguments, "func"):
            rasa.utils.io.configure_colored_logging(log_level)
            set_log_and_warnings_filters()
            rasa.telemetry.initialize_telemetry()
            rasa.telemetry.initialize_error_reporting()
            cmdline_arguments.func(cmdline_arguments)
        elif hasattr(cmdline_arguments, "version"):
            print_version()
        else:
            # user has not provided a subcommand, let's print the help
            logger.error("No command specified.")
            arg_parser.print_help()
            sys.exit(1)
    except RasaException as e:
        # these are exceptions we expect to happen (e.g. invalid training data format)
        # it doesn't make sense to print a stacktrace for these if we are not in
        # debug mode
        logger.debug("Failed to run CLI command due to an exception.",
                     exc_info=e)
        print_error(f"{e.__class__.__name__}: {e}")
        sys.exit(1)