Exemple #1
0
def set_hw_multimodal_parser(parser=None):
    """Set the parser for the hello world multimodal

    :param parser: the parser configure
    :return: the new parser
    """

    if not parser:
        parser = set_base_parser()

    mixin_hw_base_parser(parser)
    parser.add_argument(
        '--index-data-url',
        type=str,
        default='https://static.jina.ai/multimodal/people-img.zip',
        help='The url of index csv data',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=8080,
        help='The port of the host exposed to the public',
    )
    parser.add_argument(
        '--unblock-query-flow',
        action='store_true',
        default=False,
        help='Do not block the query flow' if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )
    return parser
Exemple #2
0
def set_ping_parser(parser=None):
    """Set the parser for `ping`

    :param parser: an existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    parser.add_argument(
        'host', type=str, help='The host address of the target Pod, e.g. 0.0.0.0'
    )
    parser.add_argument(
        'port', type=int, help='The control port of the target deployment/pod'
    )
    parser.add_argument(
        '--timeout',
        type=int,
        default=3000,
        help='''
Timeout in millisecond of one check
-1 for waiting forever
''',
    )
    parser.add_argument(
        '--retries',
        type=int,
        default=3,
        help='The max number of tried health checks before exit with exit code 1',
    )
    return parser
Exemple #3
0
def set_pod_parser(parser=None):
    """Set the parser for the Pod

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        from jina.parsers.base import set_base_parser

        parser = set_base_parser()

    from jina.parsers.hubble.pull import mixin_hub_pull_options_parser
    from jina.parsers.orchestrate.base import mixin_base_ppr_parser
    from jina.parsers.orchestrate.pod import mixin_pod_parser
    from jina.parsers.orchestrate.runtimes.container import (
        mixin_container_runtime_parser, )
    from jina.parsers.orchestrate.runtimes.distributed import (
        mixin_distributed_feature_parser, )
    from jina.parsers.orchestrate.runtimes.remote import mixin_remote_runtime_parser
    from jina.parsers.orchestrate.runtimes.worker import mixin_worker_runtime_parser

    mixin_base_ppr_parser(parser)
    mixin_worker_runtime_parser(parser)
    mixin_container_runtime_parser(parser)
    mixin_remote_runtime_parser(parser)
    mixin_distributed_feature_parser(parser)
    mixin_pod_parser(parser)
    mixin_hub_pull_options_parser(parser)
    mixin_head_parser(parser)

    return parser
Exemple #4
0
def set_hw_chatbot_parser(parser=None):
    """Set the parser for the hello world chatbot

    :param parser: the parser configure
    :return: the new parser
    """
    if not parser:
        parser = set_base_parser()

    mixin_hw_base_parser(parser)
    parser.add_argument(
        '--index-data-url',
        type=str,
        default='https://static.jina.ai/chatbot/dataset.csv',
        help='The url of index csv data',
    )
    parser.add_argument(
        '--port',
        type=int,
        default=8080,
        help='The port of the host exposed to the public',
    )
    parser.add_argument(
        '--replicas',
        type=int,
        default=2,
        help='The number of replicas when index and query',
    )
    parser.add_argument(
        '--unblock-query-flow',
        action='store_true',
        default=False,
        help='Do not block the query flow' if _SHOW_ALL_ARGS else argparse.SUPPRESS,
    )
    return parser
Exemple #5
0
def set_export_schema_parser(parser=None):
    """Set the parser for the API export

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    parser.add_argument(
        '--yaml-path',
        type=str,
        nargs='*',
        metavar='PATH',
        help='The YAML file path for storing the exported API',
    )
    parser.add_argument(
        '--json-path',
        type=str,
        nargs='*',
        metavar='PATH',
        help='The JSON file path for storing the exported API',
    )
    parser.add_argument(
        '--schema-path',
        type=str,
        nargs='*',
        metavar='PATH',
        help='The JSONSchema file path for storing the exported API',
    )
    return parser
Exemple #6
0
def get_main_parser():
    parser = set_base_parser()

    mixin_remote_parser(parser)

    parser.set_defaults(port_expose=8000)

    return parser
Exemple #7
0
def set_hub_new_parser(parser=None):
    """Set the parser for the hub new
    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    from jina.parsers.hubble.new import mixin_hub_new_parser

    mixin_hub_new_parser(parser)
    return parser
Exemple #8
0
def set_hw_parser(parser=None):
    """Set the hello world parser

    :param parser: the parser configure
    :return: the new parser
    """
    if not parser:
        parser = set_base_parser()

    mixin_hw_base_parser(parser)
    gp = add_arg_group(parser, title='Index')
    gp.add_argument(
        '--index-data-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz',
        help='The url of index data (should be in idx3-ubyte.gz format)',
    )
    gp.add_argument(
        '--index-labels-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz',
        help='The url of index labels data (should be in idx3-ubyte.gz format)',
    )

    gp = add_arg_group(parser, title='Search')
    gp.add_argument(
        '--query-data-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz',
        help='The url of query data (should be in idx3-ubyte.gz format)',
    )
    gp.add_argument(
        '--query-labels-url',
        type=str,
        default=
        'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz',
        help='The url of query labels data (should be in idx3-ubyte.gz format)',
    )

    gp.add_argument('--num-query',
                    type=int,
                    default=128,
                    help='The number of queries to visualize')
    gp.add_argument('--top-k',
                    type=int,
                    default=50,
                    help='Top-k results to retrieve and visualize')
    return parser
Exemple #9
0
def set_new_project_parser(parser=None):
    """Set the parser for `new`

    :param parser: an existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    parser.add_argument('name',
                        type=str,
                        help='The name of the project',
                        default='hello-jina')
    return parser
Exemple #10
0
def set_flow_parser(parser=None):
    """Set the parser for the flow

    :param parser: an (optional) initial parser to build upon
    :return: the parser
    """

    if not parser:
        parser = set_base_parser()

    mixin_essential_parser(parser)
    mixin_flow_features_parser(parser)

    return parser
Exemple #11
0
def get_main_parser():
    parser = set_base_parser()

    mixin_remote_parser(parser)
    mixin_base_ppr_parser(parser)
    mixin_daemon_parser(parser)

    parser.set_defaults(port_expose=8000,
                        log_config=os.getenv(
                            'JINAD_LOG_CONFIG',
                            resource_filename(
                                'jina', '/'.join(
                                    ('resources', 'logging.daemon.yml')))))

    return parser
Exemple #12
0
def set_flow_parser(parser=None):
    """Set the parser for the flow

    :param parser: an (optional) initial parser to build upon
    :return: the parser
    """
    from jina.parsers.orchestrate.base import mixin_base_ppr_parser

    if not parser:
        parser = set_base_parser()

    mixin_base_ppr_parser(parser)

    mixin_flow_features_parser(parser)

    return parser
Exemple #13
0
def set_export_parser(parser=None):
    """Set the parser for exporting
    :param parser: the parser configure

    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    spp = parser.add_subparsers(
        dest='export',
        description='use `%(prog)-8s [sub-command] --help` '
        'to get detailed information about each sub-command',
        required=True,
    )

    set_export_flowchart_parser(
        spp.add_parser(
            'flowchart',
            help='Export a Flow YAML file to a flowchart',
            formatter_class=_chf,
        ))

    set_export_k8s_parser(
        spp.add_parser(
            'kubernetes',
            help='Export a Flow YAML file to a Kubernetes YAML bundle',
            formatter_class=_chf,
        ))

    set_export_docker_compose_parser(
        spp.add_parser(
            'docker-compose',
            help='Export a Flow YAML file to a Docker Compose YAML file',
            formatter_class=_chf,
        ))

    set_export_schema_parser(
        spp.add_parser(
            'schema',
            help='Export Jina Executor & Flow API to JSONSchema files',
            formatter_class=_chf,
        ))

    return parser
Exemple #14
0
def set_export_k8s_parser(parser=None):
    """Set the parser for the flow chart export

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    mixin_base_io_parser(parser)

    parser.add_argument(
        '--k8s-namespace',
        type=str,
        help=
        'The name of the k8s namespace to set for the configurations. If None, the name of the Flow will be used.',
    )
    return parser
Exemple #15
0
def set_export_docker_compose_parser(parser=None):
    """Set the parser for the flow chart export

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    mixin_base_io_parser(parser)

    parser.add_argument(
        '--network_name',
        type=str,
        help=
        'The name of the network that will be used by the deployment name.',
    )
    return parser
Exemple #16
0
def set_deployment_parser(parser=None):
    """Set the parser for the Deployment

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        from jina.parsers.base import set_base_parser

        parser = set_base_parser()

    set_pod_parser(parser)

    from jina.parsers.orchestrate.deployment import mixin_base_deployment_parser

    mixin_base_deployment_parser(parser)

    return parser
Exemple #17
0
def set_help_parser(parser=None):
    """Set the parser for the jina help lookup

    :param parser: an optional existing parser to build upon
    :return: the parser
    """

    if not parser:
        from jina.parsers.base import set_base_parser

        parser = set_base_parser()

    parser.add_argument(
        'query',
        type=str,
        help='Lookup the usage & mention of the argument name in Jina API. The name can be fuzzy',
    )
    return parser
Exemple #18
0
def set_export_flowchart_parser(parser=None):
    """Set the parser for the flow chart export

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    mixin_base_io_parser(parser)

    parser.add_argument(
        '--vertical-layout',
        action='store_true',
        default=False,
        help=
        'If set, then the flowchart is rendered vertically from top to down.',
    )
    return parser
Exemple #19
0
def set_hub_parser(parser=None):
    """Set the parser for the hub
    :param parser: the parser configure

    :return: the parser
    """
    if not parser:
        parser = set_base_parser()

    spp = parser.add_subparsers(
        dest='hub',
        description='use `%(prog)-8s [sub-command] --help` '
        'to get detailed information about each sub-command',
        required=True,
    )

    set_hub_new_parser(
        spp.add_parser(
            'new',
            help='create a new executor using the template',
            description='Create a new executor using the template',
            formatter_class=_chf,
        ))

    set_hub_push_parser(
        spp.add_parser(
            'push',
            help='push an executor package to Jina hub',
            description='Push an executor package to Jina hub',
            formatter_class=_chf,
        ))

    set_hub_pull_parser(
        spp.add_parser(
            'pull',
            help='download an executor image/package from Jina hub',
            description='Download an executor image/package from Jina hub',
            formatter_class=_chf,
        ))

    return parser
Exemple #20
0
def set_gateway_parser(parser=None):
    """Set the parser for the gateway arguments

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        from jina.parsers.base import set_base_parser

        parser = set_base_parser()

    from jina.parsers.orchestrate.base import mixin_base_ppr_parser
    from jina.parsers.orchestrate.runtimes.worker import mixin_worker_runtime_parser
    from jina.parsers.orchestrate.runtimes.remote import (
        mixin_gateway_parser,
        mixin_prefetch_parser,
        mixin_http_gateway_parser,
        mixin_compressor_parser,
    )
    from jina.parsers.orchestrate.deployment import mixin_base_deployment_parser
    from jina.parsers.orchestrate.pod import mixin_pod_parser

    mixin_base_ppr_parser(parser)
    mixin_worker_runtime_parser(parser)
    mixin_prefetch_parser(parser)
    mixin_http_gateway_parser(parser)
    mixin_compressor_parser(parser)
    mixin_comm_protocol_parser(parser)
    mixin_gateway_parser(parser)
    mixin_pod_parser(parser)
    mixin_head_parser(parser)

    from jina.enums import DeploymentRoleType

    parser.set_defaults(
        name='gateway',
        runtime_cls='GRPCGatewayRuntime',
        deployment_role=DeploymentRoleType.GATEWAY,
    )

    return parser
Exemple #21
0
def set_client_cli_parser(parser=None):
    """Set the parser for the cli client

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        from jina.parsers.base import set_base_parser

        parser = set_base_parser()

    from jina.parsers.client import (
        mixin_client_features_parser,
        mixin_comm_protocol_parser,
    )
    from jina.parsers.orchestrate.runtimes.remote import mixin_client_gateway_parser

    mixin_client_gateway_parser(parser)
    mixin_client_features_parser(parser)
    mixin_comm_protocol_parser(parser)

    return parser
Exemple #22
0
def get_main_parser():
    """
    Return main parser
    :return: main parser
    """

    parser = set_base_parser()

    mixin_remote_parser(parser)
    mixin_base_ppr_parser(parser)
    mixin_daemon_parser(parser)

    parser.set_defaults(
        port_expose=8000,
        workspace='/tmp/jinad',
        log_config=os.getenv(
            'JINAD_LOG_CONFIG',
            resource_filename('jina', '/'.join(('resources', 'logging.daemon.yml'))),
        ),
    )

    return parser
Exemple #23
0
def set_hw_fork_parser(parser=None):
    """Set the parser for forking hello world demo

    :param parser: the parser configure
    :return: the new parser
    """
    if not parser:
        parser = set_base_parser()

    parser.add_argument(
        'project',
        type=str,
        choices=['fashion', 'chatbot', 'multimodal'],
        help='The hello world project to fork',
    )

    parser.add_argument(
        'destination',
        type=str,
        help='The dest directory of the forked project. Note, it can not be an existing path.',
    )

    return parser
Exemple #24
0
def get_main_parser():
    """
    Return main parser
    :return: main parser
    """

    parser = set_base_parser()

    mixin_remote_parser(parser)
    mixin_base_ppr_parser(parser)
    mixin_daemon_parser(parser)

    from jina import __resources_path__

    parser.set_defaults(
        port_expose=8000,
        workspace='/tmp/jinad',
        log_config=os.getenv(
            'JINAD_LOG_CONFIG',
            os.path.join(__resources_path__, 'logging.daemon.yml'),
        ),
    )

    return parser
Exemple #25
0
def set_hello_parser(parser=None):
    """
    Set the hello parser

    :param parser: the parser configure
    """

    if not parser:
        parser = set_base_parser()

    spp = parser.add_subparsers(
        dest='hello',
        description='use `%(prog)-8s [sub-command] --help` '
        'to get detailed information about each sub-command',
        required=True,
    )

    set_hw_parser(
        spp.add_parser(
            'fashion',
            help='Start a simple end2end fashion images index & search demo. '
            'This demo requires no extra dependencies.',
            description='Run a fashion search demo',
            formatter_class=_chf,
        )
    )

    set_hw_chatbot_parser(
        spp.add_parser(
            'chatbot',
            help='''
Start a simple Covid-19 chatbot.

Remarks:

- Pytorch, transformers & FastAPI are required to run this demo. To install all dependencies, use

    pip install "jina[demo]"

- The indexing could take 1~2 minute on a CPU machine.
''',
            description='Run a chatbot QA demo',
            formatter_class=_chf,
        )
    )

    set_hw_multimodal_parser(
        spp.add_parser(
            'multimodal',
            help='''
Start a simple multimodal document search.

Remarks:

- Pytorch, torchvision, transformers & FastAPI are required to run this demo. To install all dependencies, use

    pip install "jina[demo]"

- The indexing could take 2~3 minute on a CPU machine.
- Downloading the dataset could take ~1 minute depending on your network.
''',
            description='Run a multimodal search demo',
            formatter_class=_chf,
        )
    )

    set_hw_fork_parser(
        spp.add_parser(
            'fork',
            help='Fork a hello world project to a local directory, and start to build your own project on it.',
            description='Fork a hello world project to a local directory.',
            formatter_class=_chf,
        )
    )
Exemple #26
0
def get_main_parser():
    """The main parser for Jina

    :return: the parser
    """
    from jina.parsers.base import set_base_parser
    from jina.parsers.create import set_new_project_parser
    from jina.parsers.export_api import set_export_api_parser
    from jina.parsers.flow import set_flow_parser
    from jina.parsers.helloworld import set_hello_parser
    from jina.parsers.helper import _SHOW_ALL_ARGS, _chf
    from jina.parsers.hubble import set_hub_parser
    from jina.parsers.ping import set_ping_parser

    # create the top-level parser
    parser = set_base_parser()

    sp = parser.add_subparsers(
        dest='cli',
        required=True,
    )

    set_hello_parser(
        sp.add_parser(
            'hello',
            help='Hello Jina!',
            description='Start hello world demos.',
            formatter_class=_chf,
        ))

    set_pod_parser(
        sp.add_parser(
            'executor',
            help='Start an Executor',
            description=
            'Start an Executor. Executor is how Jina processes Document.',
            formatter_class=_chf,
        ))

    set_flow_parser(
        sp.add_parser(
            'flow',
            description=
            'Start a Flow. Flow is how Jina streamlines and distributes Executors.',
            help='Start a Flow',
            formatter_class=_chf,
        ))

    set_ping_parser(
        sp.add_parser(
            'ping',
            help='Ping an Executor',
            description='Ping a Deployment and check its network connectivity.',
            formatter_class=_chf,
        ))

    set_new_project_parser(
        sp.add_parser(
            'new',
            help='Create a new Jina project',
            description=
            'Create a new Jina toy project with the predefined template.',
            formatter_class=_chf,
        ))

    set_gateway_parser(
        sp.add_parser(
            'gateway',
            description=
            'Start a Gateway that receives client Requests via gRPC/REST interface',
            **(dict(help='Start a Gateway')) if _SHOW_ALL_ARGS else {},
            formatter_class=_chf,
        ))

    set_hub_parser(
        sp.add_parser(
            'hub',
            help='Push/pull an Executor to/from Jina Hub',
            description='Push/Pull an Executor to/from Jina Hub',
            formatter_class=_chf,
        ))

    set_help_parser(
        sp.add_parser(
            'help',
            help='Show help text of a CLI argument',
            description='Show help text of a CLI argument',
            formatter_class=_chf,
        ))
    # Below are low-level / internal / experimental CLIs, hidden from users by default

    set_pod_parser(
        sp.add_parser(
            'pod',
            description='Start a Pod. '
            'You should rarely use this directly unless you '
            'are doing low-level orchestration',
            formatter_class=_chf,
            **(dict(help='Start a Pod')) if _SHOW_ALL_ARGS else {},
        ))

    set_deployment_parser(
        sp.add_parser(
            'deployment',
            description='Start a Deployment. '
            'You should rarely use this directly unless you '
            'are doing low-level orchestration',
            formatter_class=_chf,
            **(dict(help='Start a Deployment')) if _SHOW_ALL_ARGS else {},
        ))

    set_client_cli_parser(
        sp.add_parser(
            'client',
            description=
            'Start a Python client that connects to a remote Jina gateway',
            formatter_class=_chf,
            **(dict(help='Start a Client')) if _SHOW_ALL_ARGS else {},
        ))

    set_export_api_parser(
        sp.add_parser(
            'export-api',
            description=
            'Export Jina API to JSON/YAML file for 3rd party applications',
            formatter_class=_chf,
            **(dict(help='Export Jina API to file')) if _SHOW_ALL_ARGS else {},
        ))

    return parser