Beispiel #1
0
def load(config_file, fallback_args, max_history):
    # type: (Optional[Text], Dict[Text, Any], int) -> List[Policy]
    """Load policy data stored in the specified file. fallback_args and
    max_history are typically command line arguments. They take precedence
    over the arguments specified in the config yaml.
    """

    if config_file is None:
        return PolicyEnsemble.default_policies(fallback_args, max_history)

    config_data = utils.read_yaml_file(config_file)
    config_data = handle_precedence_and_defaults(config_data, fallback_args,
                                                 max_history)

    return PolicyEnsemble.from_dict(config_data)
Beispiel #2
0
    def load_model():
        """Loads a zipped model, replacing the existing one."""

        if 'model' not in request.files:
            # model file is missing
            return error(
                400, "InvalidParameter",
                "You did not supply a model as part of your request.", {
                    "parameter": "model",
                    "in": "body"
                })

        model_file = request.files['model']

        logger.info("Received new model through REST interface.")
        zipped_path = tempfile.NamedTemporaryFile(delete=False, suffix=".zip")
        zipped_path.close()
        model_directory = tempfile.mkdtemp()

        model_file.save(zipped_path.name)

        logger.debug("Downloaded model to {}".format(zipped_path.name))

        zip_ref = zipfile.ZipFile(zipped_path.name, 'r')
        zip_ref.extractall(model_directory)
        zip_ref.close()
        logger.debug("Unzipped model to {}".format(
            os.path.abspath(model_directory)))

        ensemble = PolicyEnsemble.load(model_directory)
        agent.policy_ensemble = ensemble
        logger.debug("Finished loading new agent.")
        return '', 204
Beispiel #3
0
    def load_model():
        """Loads a zipped model, replacing the existing one."""

        if 'model' not in request.files:
            # model file is missing
            abort(400)

        model_file = request.files['model']

        logger.info("Received new model through REST interface.")
        zipped_path = tempfile.NamedTemporaryFile(delete=False, suffix=".zip")
        zipped_path.close()
        model_directory = tempfile.mkdtemp()

        model_file.save(zipped_path.name)

        logger.debug("Downloaded model to {}".format(zipped_path.name))

        zip_ref = zipfile.ZipFile(zipped_path.name, 'r')
        zip_ref.extractall(model_directory)
        zip_ref.close()
        logger.debug("Unzipped model to {}".format(
                os.path.abspath(model_directory)))

        ensemble = PolicyEnsemble.load(model_directory)
        agent.policy_ensemble = ensemble
        logger.debug("Finished loading new agent.")
        return jsonify({'success': 1})
Beispiel #4
0
    def load_model():
        """Loads a zipped model, replacing the existing one."""

        if 'model' not in request.files:
            # model file is missing
            abort(400)

        model_file = request.files['model']

        logger.info("Received new model through REST interface.")
        zipped_path = tempfile.NamedTemporaryFile(delete=False, suffix=".zip")
        zipped_path.close()
        model_directory = tempfile.mkdtemp()

        model_file.save(zipped_path.name)

        logger.debug("Downloaded model to {}".format(zipped_path.name))

        zip_ref = zipfile.ZipFile(zipped_path.name, 'r')
        zip_ref.extractall(model_directory)
        zip_ref.close()
        logger.debug("Unzipped model to {}".format(
            os.path.abspath(model_directory)))

        ensemble = PolicyEnsemble.load(model_directory)
        agent.policy_ensemble = ensemble
        logger.debug("Finished loading new agent.")
        return jsonify({'success': 1})
Beispiel #5
0
    async def load_model(request: Request):
        """Loads a zipped model, replacing the existing one."""

        if 'model' not in request.files:
            # model file is missing
            raise ErrorResponse(400, "InvalidParameter",
                                "You did not supply a model as part of your "
                                "request.",
                                {"parameter": "model", "in": "body"})

        model_file = request.files['model']

        logger.info("Received new model through REST interface.")
        zipped_path = tempfile.NamedTemporaryFile(delete=False, suffix=".zip")
        zipped_path.close()
        model_directory = tempfile.mkdtemp()

        model_file.save(zipped_path.name)

        logger.debug("Downloaded model to {}".format(zipped_path.name))

        zip_ref = zipfile.ZipFile(zipped_path.name, 'r')
        zip_ref.extractall(model_directory)
        zip_ref.close()
        logger.debug("Unzipped model to {}".format(
            os.path.abspath(model_directory)))

        domain_path = os.path.join(os.path.abspath(model_directory),
                                   "domain.yml")
        domain = Domain.load(domain_path)
        ensemble = PolicyEnsemble.load(model_directory)
        app.agent.update_model(domain, ensemble, None)
        logger.debug("Finished loading new agent.")
        return response.text('', 204)
Beispiel #6
0
def load(config_file: Optional[Text]) -> List['Policy']:
    """Load policy data stored in the specified file."""

    if config_file and os.path.isfile(config_file):
        config_data = utils.read_yaml_file(config_file)
    else:
        raise ValueError("You have to provide a valid path to a config file. "
                         "The file '{}' could not be found."
                         "".format(os.path.abspath(config_file)))

    return PolicyEnsemble.from_dict(config_data)
Beispiel #7
0
def load(config_file):
    # type: (Optional[Text], Dict[Text, Any], int) -> List[Policy]
    """Load policy data stored in the specified file. fallback_args and
    max_history are typically command line arguments. They take precedence
    over the arguments specified in the config yaml.
    """
    if config_file:
        config_data = utils.read_yaml_file(config_file)
    else:
        raise ValueError("You have to provide a config file")

    return PolicyEnsemble.from_dict(config_data)