Example #1
0
    def interact_api(config_path):
        server_conf_file = get_settings_path() / SERVER_CONFIG_FILENAME

        server_params = get_server_params(server_conf_file, config_path)
        model_args_names = server_params['model_args_names']

        url_base = 'http://{}:{}/'.format(server_params['host'], api_port or server_params['port'])
        url = urljoin(url_base.replace('http://0.0.0.0:', 'http://127.0.0.1:'), server_params['model_endpoint'])

        post_headers = {'Accept': 'application/json'}

        post_payload = {}
        for arg_name in model_args_names:
            arg_value = str(' '.join(['qwerty'] * 10))
            post_payload[arg_name] = [arg_value]

        logfile = io.BytesIO(b'')
        args = [sys.executable, "-m", "deeppavlov", "riseapi", str(config_path)]
        if api_port:
            args += ['-p', str(api_port)]
        p = pexpect.popen_spawn.PopenSpawn(' '.join(args),
                                           timeout=None, logfile=logfile)
        try:
            p.expect(url_base)
            post_response = requests.post(url, json=post_payload, headers=post_headers)
            response_code = post_response.status_code
            assert response_code == 200, f"POST request returned error code {response_code} with {config_path}"

        except pexpect.exceptions.EOF:
            raise RuntimeError('Got unexpected EOF: \n{}'.format(logfile.getvalue().decode()))

        finally:
            p.kill(signal.SIGTERM)
            p.wait()
Example #2
0
def start_alice_server(model_config, https=False, ssl_key=None, ssl_cert=None):
    server_config_path = get_settings_path() / SERVER_CONFIG_FILENAME
    server_params = get_server_params(server_config_path, model_config)

    https = https or server_params['https']

    if not https:
        ssl_key = ssl_cert = None
    else:
        ssh_key = Path(ssl_key or server_params['https_key_path']).resolve()
        if not ssh_key.is_file():
            e = FileNotFoundError(
                'Ssh key file not found: please provide correct path in --key param or '
                'https_key_path param in server configuration file')
            log.error(e)
            raise e

        ssh_cert = Path(ssl_cert or server_params['https_cert_path']).resolve()
        if not ssh_cert.is_file():
            e = FileNotFoundError(
                'Ssh certificate file not found: please provide correct path in --cert param or '
                'https_cert_path param in server configuration file')
            log.error(e)
            raise e

    host = server_params['host']
    port = server_params['port']
    model_endpoint = server_params['model_endpoint']

    model = build_model(model_config)
    skill = DefaultStatelessSkill(model, lang='ru')
    agent = DefaultAgent([skill], skills_processor=DefaultRichContentWrapper())

    start_agent_server(agent, host, port, model_endpoint, ssl_key, ssl_cert)
Example #3
0
    def interact_api(config_path):
        server_conf_file = get_settings_path() / SERVER_CONFIG_FILENAME

        server_params = get_server_params(server_conf_file, config_path)
        model_args_names = server_params['model_args_names']

        url_base = 'http://{}:{}/'.format(server_params['host'], api_port or server_params['port'])
        url = urljoin(url_base.replace('http://0.0.0.0:', 'http://127.0.0.1:'), server_params['model_endpoint'])

        post_headers = {'Accept': 'application/json'}

        post_payload = {}
        for arg_name in model_args_names:
            arg_value = str(' '.join(['qwerty'] * 10))
            post_payload[arg_name] = [arg_value]

        logfile = io.BytesIO(b'')
        args = [sys.executable, "-m", "deeppavlov", "riseapi", str(config_path)]
        if api_port:
            args += ['-p', str(api_port)]
        p = pexpect.popen_spawn.PopenSpawn(' '.join(args),
                                           timeout=None, logfile=logfile)
        try:
            p.expect(url_base)
            post_response = requests.post(url, json=post_payload, headers=post_headers)
            response_code = post_response.status_code
            assert response_code == 200, f"POST request returned error code {response_code} with {config_path}"

        except pexpect.exceptions.EOF:
            raise RuntimeError('Got unexpected EOF: \n{}'.format(logfile.getvalue().decode()))

        finally:
            p.kill(signal.SIGTERM)
            p.wait()
Example #4
0
    def interact_api(conf_file):
        server_conf_file = Path(
            tests_dir,
            "..").resolve() / "utils" / "server_utils" / SERVER_CONFIG_FILENAME

        server_params = get_server_params(server_conf_file, conf_file)
        model_args_names = server_params['model_args_names']

        url_base = 'http://{}:{}/'.format(server_params['host'],
                                          server_params['port'])
        url = urljoin(url_base, server_params['model_endpoint'])

        post_headers = {'Accept': 'application/json'}

        post_payload = {}
        for arg_name in model_args_names:
            arg_value = str(' '.join(['qwerty'] * 10))
            post_payload[arg_name] = [arg_value]

        logfile = io.BytesIO(b'')
        p = pexpect.spawn(sys.executable,
                          ["-m", "deeppavlov", "riseapi",
                           str(conf_file)],
                          timeout=None,
                          logfile=logfile)
        try:
            p.expect(url_base)
            post_response = requests.post(url,
                                          json=post_payload,
                                          headers=post_headers)
            response_code = post_response.status_code
            assert response_code == 200, f"POST request returned error code {response_code} with {conf_file}"

        except pexpect.exceptions.EOF:
            logfile.seek(0)
            raise RuntimeError('Got unexpected EOF: \n{}'.format(''.join(
                (line.decode() for line in logfile.readlines()))))

        finally:
            p.send(chr(3))
            if p.expect(pexpect.EOF) != 0:
                logfile.seek(0)
                raise RuntimeError(
                    'Error in shutting down API server: \n{}'.format(''.join(
                        (line.decode() for line in logfile.readlines()))))
Example #5
0
def start_alice_server(model_config_path,
                       https=False,
                       ssl_key=None,
                       ssl_cert=None):
    if not https:
        ssl_key = ssl_cert = None

    server_config_dir = Path(__file__).parent
    server_config_path = server_config_dir.parent / SERVER_CONFIG_FILENAME

    server_params = get_server_params(server_config_path, model_config_path)
    host = server_params['host']
    port = server_params['port']
    model_endpoint = server_params['model_endpoint']

    model = init_model(model_config_path)
    skill = DefaultStatelessSkill(model, lang='ru')
    agent = DefaultAgent([skill], skills_processor=DefaultRichContentWrapper())

    start_agent_server(agent, host, port, model_endpoint, ssl_key, ssl_cert)
    def interact_api(conf_file):
        server_conf_file = Path(utils.__path__[0]) / "server_utils" / SERVER_CONFIG_FILENAME

        server_params = get_server_params(server_conf_file, conf_file)
        model_args_names = server_params['model_args_names']

        url_base = 'http://{}:{}/'.format(server_params['host'], server_params['port'])
        url = urljoin(url_base, server_params['model_endpoint'])

        post_headers = {'Accept': 'application/json'}

        post_payload = {}
        for arg_name in model_args_names:
            arg_value = str(' '.join(['qwerty'] * 10))
            post_payload[arg_name] = [arg_value]

        logfile = io.BytesIO(b'')
        p = pexpect.spawn(sys.executable, ["-m", "deeppavlov", "riseapi", str(conf_file)], timeout=None,
                          logfile=logfile)
        try:
            p.expect(url_base)
            post_response = requests.post(url, json=post_payload, headers=post_headers)
            response_code = post_response.status_code
            assert response_code == 200, f"POST request returned error code {response_code} with {conf_file}"

        except pexpect.exceptions.EOF:
            logfile.seek(0)
            raise RuntimeError('Got unexpected EOF: \n{}'
                               .format(''.join((line.decode() for line in logfile.readlines()))))

        finally:
            p.send(chr(3))
            if p.expect(pexpect.EOF) != 0:
                logfile.seek(0)
                raise RuntimeError('Error in shutting down API server: \n{}'
                                   .format(''.join((line.decode() for line in logfile.readlines()))))