python/ray/serve/api.py
def run(
    target: Union[ClassNode, FunctionNode],
    _blocking: bool = True,
    *,
    host: str = DEFAULT_HTTP_HOST,
    port: int = DEFAULT_HTTP_PORT,
) -> Optional[RayServeHandle]:
    """Run a Serve application and return a ServeHandle to the ingress.

    Either a ClassNode, FunctionNode, or a pre-built application
    can be passed in. If a node is passed in, all of the deployments it depends
    on will be deployed. If there is an ingress, its handle will be returned.

    Args:
        target (Union[ClassNode, FunctionNode, Application]):
            A user-built Serve Application or a ClassNode that acts as the
            root node of DAG. By default ClassNode is the Driver
            deployment unless user provides a customized one.
        host (str): The host passed into serve.start().
        port (int): The port passed into serve.start().

    Returns:
        RayServeHandle: A regular ray serve handle that can be called by user
            to execute the serve DAG.
    """
    # TODO (jiaodong): Resolve circular reference in pipeline codebase and serve
    from ray.serve.pipeline.api import build as pipeline_build
    from ray.serve.pipeline.api import get_and_validate_ingress_deployment

    client = start(detached=True, http_options={"host": host, "port": port})

    if isinstance(target, Application):
        deployments = list(target.deployments.values())
        ingress = target.ingress
    # Each DAG should always provide a valid Driver ClassNode
    elif isinstance(target, ClassNode):
        deployments = pipeline_build(target)
        ingress = get_and_validate_ingress_deployment(deployments)
    # Special case where user is doing single function serve.run(func.bind())
    elif isinstance(target, FunctionNode):
        deployments = pipeline_build(target)
        ingress = get_and_validate_ingress_deployment(deployments)
        if len(deployments) != 1:
            raise ValueError(
                "We only support single function node in serve.run, ex: "
                "serve.run(func.bind()). For more than one nodes in your DAG, "
                "Please provide a driver class and bind it as entrypoint to "
                "your Serve DAG."
            )
    elif isinstance(target, DAGNode):
        raise ValueError(
            "Invalid DAGNode type as entry to serve.run(), "
            f"type: {type(target)}, accepted: ClassNode, "
            "FunctionNode please provide a driver class and bind it "
            "as entrypoint to your Serve DAG."
        )
    else:
        raise TypeError(
            "Expected a ClassNode, FunctionNode, or Application as target. "
            f"Got unexpected type {type(target)} instead."
        )

    parameter_group = []

    for deployment in deployments:
        deployment_parameters = {
            "name": deployment._name,
            "func_or_class": deployment._func_or_class,
            "init_args": deployment.init_args,
            "init_kwargs": deployment.init_kwargs,
            "ray_actor_options": deployment._ray_actor_options,
            "config": deployment._config,
            "version": deployment._version,
            "prev_version": deployment._prev_version,
            "route_prefix": deployment.route_prefix,
            "url": deployment.url,
        }

        parameter_group.append(deployment_parameters)

    client.deploy_group(parameter_group, _blocking=_blocking)

    if ingress is not None:
        return ingress.get_handle()
Run a Serve application and return a ServeHandle to the ingress.

    Either a ClassNode, FunctionNode, or a pre-built application
    can be passed in. If a node is passed in, all of the deployments it depends
    on will be deployed. If there is an ingress, its handle will be returned.

    Args:
        target (Union[ClassNode, FunctionNode, Application]):
            A user-built Serve Application or a ClassNode that acts as the
            root node of DAG. By default ClassNode is the Driver
            deployment unless user provides a customized one.
        host (str): The host passed into serve.start().
        port (int): The port passed into serve.start().

    Returns:
        RayServeHandle: A regular ray serve handle that can be called by user
            to execute the serve DAG.
    
Run a Serve application and return a ServeHandle to the ingress.
Either a ClassNode, FunctionNode, or a pre-built application
can be passed in. If a node is passed in, all of the deployments it depends
on will be deployed. If there is an ingress, its handle will be returned.
Run a Serve application and return a ServeHandle to the ingress . Either a ClassNode FunctionNode or a pre - built application can be passed in . If a node is passed in all of the deployments it depends on will be deployed . If there is an ingress its handle will be returned .
def run(
    target: Union[ClassNode, FunctionNode],
    _blocking: bool = True,
    *,
    host: str = DEFAULT_HTTP_HOST,
    port: int = DEFAULT_HTTP_PORT,
) -> Optional[RayServeHandle]:
    from ray.serve.pipeline.api import build as pipeline_build
    from ray.serve.pipeline.api import get_and_validate_ingress_deployment
    client = start(detached=True, http_options={"host": host, "port": port})
    if isinstance(target, Application):
        deployments = list(target.deployments.values())
        ingress = target.ingress
    elif isinstance(target, ClassNode):
        deployments = pipeline_build(target)
        ingress = get_and_validate_ingress_deployment(deployments)
    elif isinstance(target, FunctionNode):
        deployments = pipeline_build(target)
        ingress = get_and_validate_ingress_deployment(deployments)
        if len(deployments) != 1:
            raise ValueError(
                "We only support single function node in serve.run, ex: "
                "serve.run(func.bind()). For more than one nodes in your DAG, "
                "Please provide a driver class and bind it as entrypoint to "
                "your Serve DAG."
            )
    elif isinstance(target, DAGNode):
        raise ValueError(
            "Invalid DAGNode type as entry to serve.run(), "
            f"type: {type(target)}, accepted: ClassNode, "
            "FunctionNode please provide a driver class and bind it "
            "as entrypoint to your Serve DAG."
        )
    else:
        raise TypeError(
            "Expected a ClassNode, FunctionNode, or Application as target. "
            f"Got unexpected type {type(target)} instead."
        )
    parameter_group = []
    for deployment in deployments:
        deployment_parameters = {
            "name": deployment._name,
            "func_or_class": deployment._func_or_class,
            "init_args": deployment.init_args,
            "init_kwargs": deployment.init_kwargs,
            "ray_actor_options": deployment._ray_actor_options,
            "config": deployment._config,
            "version": deployment._version,
            "prev_version": deployment._prev_version,
            "route_prefix": deployment.route_prefix,
            "url": deployment.url,
        }
        parameter_group.append(deployment_parameters)
    client.deploy_group(parameter_group, _blocking=_blocking)
    if ingress is not None:
        return ingress.get_handle()
def run ( target : Union [ ClassNode , FunctionNode ] , _blocking : bool = True , * , host : str = DEFAULT_HTTP_HOST , port : int = DEFAULT_HTTP_PORT , ) -> Optional [ RayServeHandle ] : from ray . serve . pipeline . api import build as pipeline_build from ray . serve . pipeline . api import get_and_validate_ingress_deployment client = start ( detached = True , http_options = { "host" : host , "port" : port } ) if isinstance ( target , Application ) : deployments = list ( target . deployments . values ( ) ) ingress = target . ingress elif isinstance ( target , ClassNode ) : deployments = pipeline_build ( target ) ingress = get_and_validate_ingress_deployment ( deployments ) elif isinstance ( target , FunctionNode ) : deployments = pipeline_build ( target ) ingress = get_and_validate_ingress_deployment ( deployments ) if len ( deployments ) != 1 : raise ValueError ( "We only support single function node in serve.run, ex: " "serve.run(func.bind()). For more than one nodes in your DAG, " "Please provide a driver class and bind it as entrypoint to " "your Serve DAG." ) elif isinstance ( target , DAGNode ) : raise ValueError ( "Invalid DAGNode type as entry to serve.run(), " f"type: {type(target)}, accepted: ClassNode, " "FunctionNode please provide a driver class and bind it " "as entrypoint to your Serve DAG." ) else : raise TypeError ( "Expected a ClassNode, FunctionNode, or Application as target. " f"Got unexpected type {type(target)} instead." ) parameter_group = [ ] for deployment in deployments : deployment_parameters = { "name" : deployment . _name , "func_or_class" : deployment . _func_or_class , "init_args" : deployment . init_args , "init_kwargs" : deployment . init_kwargs , "ray_actor_options" : deployment . _ray_actor_options , "config" : deployment . _config , "version" : deployment . _version , "prev_version" : deployment . _prev_version , "route_prefix" : deployment . route_prefix , "url" : deployment . url , } parameter_group . append ( deployment_parameters ) client . deploy_group ( parameter_group , _blocking = _blocking ) if ingress is not None : return ingress . get_handle ( )
Run a Serve application and return a ServeHandle to the ingress.
Run a Serve application and return a ServeHandle to the ingress .
"""Run a Serve application and return a ServeHandle to the ingress.

    Either a ClassNode, FunctionNode, or a pre-built application
    can be passed in. If a node is passed in, all of the deployments it depends
    on will be deployed. If there is an ingress, its handle will be returned.

    Args:
        target (Union[ClassNode, FunctionNode, Application]):
            A user-built Serve Application or a ClassNode that acts as the
            root node of DAG. By default ClassNode is the Driver
            deployment unless user provides a customized one.
        host (str): The host passed into serve.start().
        port (int): The port passed into serve.start().

    Returns:
        RayServeHandle: A regular ray serve handle that can be called by user
            to execute the serve DAG.
    """ # TODO (jiaodong): Resolve circular reference in pipeline codebase and serve # Each DAG should always provide a valid Driver ClassNode # Special case where user is doing single function serve.run(func.bind())
A regular ray serve handle that can be called by user
to execute the serve DAG.
A regular ray serve handle that can be called by user to execute the serve DAG .
RayServeHandle
target
Union[ClassNode, FunctionNode]
A user-built Serve Application or a ClassNode that acts as the
root node of DAG. By default ClassNode is the Driver
deployment unless user provides a customized one.
A user - built Serve Application or a ClassNode that acts as the root node of DAG . By default ClassNode is the Driver deployment unless user provides a customized one .
_blocking
bool
host
str
The host passed into serve.start().
The host passed into serve . start () .
port
int
The port passed into serve.start().
The port passed into serve . start () .