コード例 #1
0
ファイル: test_helloworld.py プロジェクト: tyunist/jina
def test_helloworld_flow(tmpdir):
    args = set_hw_parser().parse_args([])

    os.environ['RESOURCE_DIR'] = resource_filename('jina', 'resources')
    os.environ['SHARDS'] = str(args.shards)
    os.environ['PARALLEL'] = str(args.parallel)
    os.environ['HW_WORKDIR'] = str(tmpdir)
    os.environ['WITH_LOGSERVER'] = str(args.logserver)

    f = Flow.load_config(
        resource_filename('jina', '/'.join(
            ('resources', 'helloworld.flow.index.yml'))))

    targets = {
        'index': {
            'url': args.index_data_url,
            'filename': os.path.join(tmpdir, 'index-original')
        },
        'query': {
            'url': args.query_data_url,
            'filename': os.path.join(tmpdir, 'query-original')
        }
    }

    # download the data
    Path(tmpdir).mkdir(parents=True, exist_ok=True)
    download_data(targets)

    # run it!
    with f:
        py_client(
            host=f.host,
            port_expose=f.port_expose,
        ).index(input_numpy(targets['index']['data']),
                batch_size=args.index_batch_size)
コード例 #2
0
ファイル: http_query.py プロジェクト: yuanbit/examples
def main(text, host, top_k):
    py_client(host=host, port_expose=56798).dry_run()
    ppr = lambda x: print_topk(x, text)

    py_client(host=host, port_expose=56798,
              top_k=top_k).search(input_fn=read_query_data(text),
                                  output_fn=ppr)
コード例 #3
0
ファイル: test_flow.py プロジェクト: alfred297/Pooja-AI
    def test_py_client(self):
        f = (Flow().add(name='r1', yaml_path='_forward').add(
            name='r2', yaml_path='_forward').add(
                name='r3', yaml_path='_forward', needs='r1').add(
                    name='r4', yaml_path='_forward',
                    needs='r2').add(name='r5',
                                    yaml_path='_forward',
                                    needs='r3').add(
                                        name='r6',
                                        yaml_path='_forward',
                                        needs='r4').add(
                                            name='r8',
                                            yaml_path='_forward',
                                            needs='r6').add(
                                                name='r9',
                                                yaml_path='_forward',
                                                needs='r5').add(
                                                    name='r10',
                                                    yaml_path='_merge',
                                                    needs=['r9', 'r8']))

        with f:
            f.dry_run()
            from jina.clients import py_client
            py_client(port_grpc=f.port_grpc, host=f.host).dry_run()
コード例 #4
0
def test_py_client():
    f = (Flow().add(name='r1')
         .add(name='r2')
         .add(name='r3', needs='r1')
         .add(name='r4', needs='r2')
         .add(name='r5', needs='r3')
         .add(name='r6', needs='r4')
         .add(name='r8', needs='r6')
         .add(name='r9', needs='r5')
         .add(name='r10', needs=['r9', 'r8']))

    with f:
        f.dry_run()
        from jina.clients import py_client
        py_client(port_expose=f.port_expose, host=f.host).dry_run(IndexDryRunRequest())

    with f:
        node = f._pod_nodes['gateway']
        assert node.head_args.socket_in == SocketType.PULL_CONNECT
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r1']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUB_BIND

        node = f._pod_nodes['r2']
        assert node.head_args.socket_in == SocketType.SUB_CONNECT
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r3']
        assert node.head_args.socket_in == SocketType.SUB_CONNECT
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r4']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r5']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r6']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r8']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r9']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUSH_CONNECT

        node = f._pod_nodes['r10']
        assert node.head_args.socket_in == SocketType.PULL_BIND
        assert node.tail_args.socket_out == SocketType.PUSH_BIND

        for name, node in f._pod_nodes.items():
            assert node.peas_args['peas'][0] == node.head_args
            assert node.peas_args['peas'][0] == node.tail_args
コード例 #5
0
def search():
    observable = Observable()
    query = request.get_json()
    py_client(host="localhost", port_expose=server_port,
              top_k=100).search(input_fn=read_query_data(query["searchQuery"]),
                                output_fn=lambda x: observable.callback(x))
    results = observable.format_response()
    return jsonify(results)
コード例 #6
0
async def test_client_call_unary(flow):
    with flow:
        client = py_client(port_expose=flow.port_expose)
        await client.configure_client()
        await client.call_unary(
            [b'a1234', b'b4567'],
            mode=RequestType.INDEX,
        )
コード例 #7
0
def hello_world(args):
    Path(args.workdir).mkdir(parents=True, exist_ok=True)

    targets = {
        'index': {
            'url': args.index_data_url,
            'filename': os.path.join(args.workdir, 'index-original')
        },
        'query': {
            'url': args.query_data_url,
            'filename': os.path.join(args.workdir, 'query-original')
        }
    }

    # download the data
    download_data(targets)

    # run it!
    py_client(port_grpc=args.port_grpc, host=args.host).index(
        input_fn(targets['index']['filename']), batch_size=args.index_batch_size)
コード例 #8
0
ファイル: test_client.py プロジェクト: yashmehta5/jina
def test_client():
    f = Flow().add(uses='_pass')
    with f:
        print(
            py_client(port_expose=f.port_expose).call_unary(
                b'a1234', mode=ClientMode.INDEX))
コード例 #9
0
def test_client(flow):
    with flow:
        py_client(port_expose=flow.port_expose).call_unary(
            b'a1234', mode=ClientMode.INDEX)
コード例 #10
0
async def test_client_search(flow):
    with flow:
        client = py_client(port_expose=flow.port_expose)
        await client.configure_client()
        await client.search(['a1234', 'b4567'])
コード例 #11
0
 def test_client(self):
     f = Flow().add(yaml_path='_forward')
     with f:
         print(
             py_client(port_grpc=f.port_grpc).call_unary(
                 b'a1234', mode=ClientMode.INDEX))
コード例 #12
0
    def test_py_client(self):
        f = (Flow().add(name='r1', yaml_path='_forward').add(
            name='r2', yaml_path='_forward').add(
                name='r3', yaml_path='_forward', needs='r1').add(
                    name='r4', yaml_path='_forward',
                    needs='r2').add(name='r5',
                                    yaml_path='_forward',
                                    needs='r3').add(
                                        name='r6',
                                        yaml_path='_forward',
                                        needs='r4').add(
                                            name='r8',
                                            yaml_path='_forward',
                                            needs='r6').add(
                                                name='r9',
                                                yaml_path='_forward',
                                                needs='r5').add(
                                                    name='r10',
                                                    yaml_path='_merge',
                                                    needs=['r9', 'r8']))

        with f:
            f.dry_run()
            from jina.clients import py_client
            py_client(port_expose=f.port_expose,
                      host=f.host).dry_run(as_request='index')

        with f:
            self.assertEqual(f._pod_nodes['gateway'].head_args.socket_in,
                             SocketType.PULL_CONNECT)
            self.assertEqual(f._pod_nodes['gateway'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r1'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r1'].tail_args.socket_out,
                             SocketType.PUB_BIND)

            self.assertEqual(f._pod_nodes['r2'].head_args.socket_in,
                             SocketType.SUB_CONNECT)
            self.assertEqual(f._pod_nodes['r2'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r3'].head_args.socket_in,
                             SocketType.SUB_CONNECT)
            self.assertEqual(f._pod_nodes['r3'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r4'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r4'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r5'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r5'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r6'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r6'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r8'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r8'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r9'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r9'].tail_args.socket_out,
                             SocketType.PUSH_CONNECT)

            self.assertEqual(f._pod_nodes['r10'].head_args.socket_in,
                             SocketType.PULL_BIND)
            self.assertEqual(f._pod_nodes['r10'].tail_args.socket_out,
                             SocketType.PUSH_BIND)

            for name, node in f._pod_nodes.items():
                self.assertEqual(node.peas_args['peas'][0], node.head_args)
                self.assertEqual(node.peas_args['peas'][0], node.tail_args)
コード例 #13
0
ファイル: test_client.py プロジェクト: zatcsc/jina
def test_client(flow):
    with flow:
        py_client(port_expose=flow.port_expose).call_unary(
            [b'a1234', b'b4567'],
            mode=RequestType.INDEX,
        )