Exemplo n.º 1
0
Arquivo: agent.py Projeto: zoovu/rasa
async def _update_model_from_server(model_server: EndpointConfig, agent: Agent) -> None:
    """Load a zipped Rasa Core model from a URL and update the passed agent."""
    if not is_url(model_server.url):
        raise aiohttp.InvalidURL(model_server.url)

    with tempfile.TemporaryDirectory() as temporary_directory:
        try:
            new_fingerprint = await _pull_model_and_fingerprint(
                model_server, agent.fingerprint, temporary_directory
            )

            if new_fingerprint:
                _load_and_set_updated_model(agent, temporary_directory, new_fingerprint)
            else:
                logger.debug(f"No new model found at URL {model_server.url}")
        except Exception:  # skipcq: PYL-W0703
            # TODO: Make this exception more specific, possibly print different log
            # for each one.
            logger.exception(
                "Failed to update model. The previous model will stay loaded instead."
            )
Exemplo n.º 2
0
async def _update_model_from_server(
    model_server: EndpointConfig,
    nlu_model: "NLUModel",
    component_builder: ComponentBuilder,
) -> None:
    """Load a tar.gz Rasa NLU model from a URL and update the passed
    nlu model."""
    if not is_url(model_server.url):
        raise InvalidURL(model_server)

    model_directory = tempfile.mkdtemp()

    new_model_fingerprint, filename = await _pull_model_and_fingerprint(
        model_server, model_directory, nlu_model.fingerprint
    )

    if new_model_fingerprint:
        model_name = _get_remote_model_name(filename)
        nlu_model.fingerprint = new_model_fingerprint
        nlu_model.update_model(component_builder, model_directory, model_name)
    else:
        logger.debug("No new model found at URL '{}'".format(model_server.url))