o
    `۷i(                  
   @   s  d dl Z d dlZd dlmZ d dlmZmZmZ d dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZmZ d dlmZmZ d dlmZ d dlm Z  d dl!m"Z" e#eZ$dedee%ef ddfddZ&			d dede%ef dede%ef dede%e"f defddZ'			d dede%ef dede%ef dede%e"f defddZ(			d dede%ef dede%ef dede%e"f defddZ)deeef dee*ef defddZ+dS )!    N)FunctionType)AnyDictUnion)is_subclass_of_base_model)	usage_lib)ActorHandle)ServeControllerClient)HTTP_PROXY_TIMEOUTSERVE_LOGGER_NAMESERVE_NAMESPACE)get_controller_impl)HTTPOptionsgRPCOptions)_get_global_client_set_global_client)Application)RayServeException)LoggingConfigclienthttp_optionsreturnc                 C   sz   |r9| j }t|tr|nt|}g }|j}|D ]}t||t||kr)|| qt|r;t	d| d d S d S d S )NzRThe new client HTTP config differs from the existing one in the following fields: z!. The new HTTP config is ignored.)
http_config
isinstancer   	parse_obj__dict__getattrappendlenloggerwarning)r   r   client_http_optionsnew_http_optionsdifferent_fieldsall_http_option_fieldsfield r&   L/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/serve/_private/api.py_check_http_options   s(   
r(   grpc_optionsglobal_logging_configc           	      K   s6  dt jjj_t  st jtd g d}|D ]}||v r+t| d| d||  dqt	| t
r6t| } | du r=t } t	|t
rItdi |}|du rQt }nt	|t
r]tdi |}t }|j| ||d}t |j }t|d	krzt jd
d | D td W |S  t jjy   tdt dw |S )zStart Ray Serve controller.

    The function makes sure controller is ready to start deploying apps
    after it returns.

    Parameters are same as ray.serve._private.api.serve_start().

    Returns: controller actor handle.
    F)	namespace)	http_host	http_porthttp_middlewaresz6 is deprecated, please use serve.start(http_options={"z": z}) instead.N)r   r)   r*   r   c                 S   s   g | ]}|j  qS r&   )readyremote).0handler&   r&   r'   
<listcomp>h   s    z%_start_controller.<locals>.<listcomp>)timeoutz!HTTP proxies not available after zs.r&   )ray_privateworkerglobal_worker_filter_logs_by_jobis_initializedinitr   
ValueErrorr   dictr   r   r   r   r   r0   getget_proxiesr   valuesr
   
exceptionsGetTimeoutErrorTimeoutError)	r   r)   r*   kwargshttp_deprecated_argskeycontroller_impl
controllerproxy_handlesr&   r&   r'   _start_controller2   sX   




rJ   c                    s   t d ztdd}tdt d | rt||  |W S  ty'   Y nw t	t
jddj	| ||fi |I dH }t|}t| td	t d
 |S )a]  Initialize a serve instance asynchronously.

    This function is not thread-safe. The caller should maintain the async lock in order
    to start the serve instance asynchronously.

    This function has the same functionality as ray.serve._private.api.serve_start().

    Parameters & Returns are same as ray.serve._private.api.serve_start().
    serveT_health_check_controller/Connecting to existing Serve app in namespace "(". New http options will not be applied.r   )num_cpusNStarted Serve in namespace "".)r   record_library_usager   r   infor   r(   r   r5   r0   rJ   optionsr	   r   r   r)   r*   rD   r   rH   r&   r&   r'   serve_start_asyncr   s6   




rW   c                 K   s   t d ztdd}tdt d | rt||  |W S  ty&   Y nw t| ||fi |}t	|}t
| tdt d |S )a2  Initialize a serve instance.

    By default, the instance will be scoped to the lifetime of the returned
    Client object (or when the script exits). This is
    only relevant if connecting to a long-running Ray cluster (e.g., with
    ray.init(address="auto") or ray.init("ray://<remote_addr>")).

    Args:
        http_options (Optional[Dict, serve.HTTPOptions]): Configuration options
          for HTTP proxy. You can pass in a dictionary or HTTPOptions object
          with fields:

            - host(str, None): Host for HTTP servers to listen on. Defaults to
              "127.0.0.1". To expose Serve publicly, you probably want to set
              this to "0.0.0.0".
            - port(int): Port for HTTP server. Defaults to 8000.
            - root_path(str): Root path to mount the serve application
              (for example, "/serve"). All deployment routes will be prefixed
              with this path. Defaults to "".
            - middlewares(list): A list of Starlette middlewares that will be
              applied to the HTTP servers in the cluster. Defaults to [].
            - location(str, serve.config.DeploymentMode): The deployment
              location of HTTP servers:

                - "HeadOnly": start one HTTP server on the head node. Serve
                  assumes the head node is the node you executed serve.start
                  on. This is the default.
                - "EveryNode": start one HTTP server per node.
                - "NoServer" or None: disable HTTP server.
            - num_cpus (int): The number of CPU cores to reserve for each
              internal Serve HTTP proxy actor.  Defaults to 0.
        grpc_options: [Experimental] Configuration options for gRPC proxy.
          You can pass in a gRPCOptions object with fields:

            - port(int): Port for gRPC server. Defaults to 9000.
            - grpc_servicer_functions(list): List of import paths for gRPC
                `add_servicer_to_server` functions to add to Serve's gRPC proxy.
                Default empty list, meaning not to start the gRPC server.
    rK   TrL   rN   rO   rQ   rR   )r   rS   r   r   rT   r   r(   r   rJ   r	   r   rV   r&   r&   r'   serve_start   s.   
.


rX   builderargsc                 C   s   t | trt|dkrtd| S t | ts tdt|  dt| }t|j	dkr0td|j	t
|j	 d  }t|jrMt|jrM|j|}| |}t |ts`tdt| d|S )ab  Calls a user-provided function that returns Serve application.

    If an Application object is passed, this is a no-op.

    Else, we validate the signature of the function, convert the args dictionary to
    the user-annotated Pydantic model if provided, and call the function.

    The output of the function is returned (must be an Application).
    r   zbArguments can only be passed to an application builder function, not an already built application.zOExpected a built Serve application or an application builder function but got: .   znApplication builder functions should take exactly one parameter, a dictionary containing the passed arguments.zhApplication builder functions must return an `Application` returned `from `Deployment.bind()`, but got: )r   r   r   r<   r   	TypeErrortypeinspect	signature
parameterslistkeysisclass
annotationr   r   )rY   rZ   r`   paramappr&   r&   r'   ,call_user_app_builder_with_args_if_necessary   s<   



rh   )NNN),r_   loggingtypesr   typingr   r   r   r5   ray._common.pydantic_compatr   ray._common.usager   	ray.actorr   ray.serve._private.clientr	   ray.serve._private.constantsr
   r   r   ray.serve._private.default_implr   ray.serve.configr   r   ray.serve.contextr   r   ray.serve.deploymentr   ray.serve.exceptionsr   ray.serve.schemar   	getLoggerr   r=   r(   rJ   rW   rX   strrh   r&   r&   r&   r'   <module>   s    



A
-
H

