
    &`i(              
       L   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j#        e          Z$dedee%ef         ddf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Z'	 	 	 ddede%ef         dede%ef         dede%e"f         def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Z)deeef         dee*ef         def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                 Z   |r| j         }t          |t                    r|nt          j        |          }g }|j        }|D ]9}t          ||          t          ||          k    r|                    |           :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fields          j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/_private/api.py_check_http_optionsr)      s      $0 ,445LL&|44 	
 !1!:+ 	/ 	/E'//7;NPU3V3VVV ''...   	NN2,<2 2 2     	 	    grpc_optionsglobal_logging_configc           	         dt           j        j        j        _        t          j                    st          j        t                     g d}|D ]$}||v rt          | d| d||          d          %t          | t                    rt          j        |           } | t                      } t          |t                    rt          di |}|t                      }n!t          |t                    rt          di |}t                      }|                    | ||          }t          j        |j                                                  }t'          |          d	k    ri	 t          j        d
 |                                D             t*                     n0# t           j        j        $ r t1          dt*           d          w xY 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                 @    g | ]}|j                                         S  )readyremote).0handles     r(   
<listcomp>z%_start_controller.<locals>.<listcomp>h   s&    LLL6$$&&LLLr*   )timeoutz!HTTP proxies not available after zs.r3   )ray_privateworkerglobal_worker_filter_logs_by_jobis_initializedinitr   
ValueErrorr   dictr   r   r   r   r   r5   getget_proxiesr    valuesr   
exceptionsGetTimeoutErrorTimeoutError)	r   r+   r,   kwargshttp_deprecated_argskeycontroller_impl
controllerproxy_handless	            r(   _start_controllerrO   2   s*   " =BCL%9 ,?++++ JII#  &== 8 88 8$Sk8 8 8    ,%% ;",\::"}},%% 3"22\22$ -	)4	0	0 G - F F0E F F)++O ''!!3 (  J GJ299;;<<M
=A	GLL]5I5I5K5KLLL*     ~- 	 	 	J4FJJJ  	 s   %7F -G
c                   K   t          j        d           	 t          d          }t                              dt
           d           | rt          ||            |S # t          $ r Y nw xY w t          j	        t                                        d          j	        | ||fi | d{V }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   r:   r5   rO   optionsr
   r   r   r+   r,   rI   r   rM   s         r(   serve_start_asyncr]   r   sO       "7+++
#TBBB5o 5 5 5	
 	
 	
  	6555   cj*++	!			l,AM MEKM M 	M 	M 	M 	M 	M 	M  # F v
KKBBBBCCCMs   AA 
A,+A,c                 ~   t          j        d           	 t          d          }t                              dt
           d           | rt          ||            |S # t          $ r Y nw xY 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.
    rQ   TrR   rT   rU   rW   rX   )r   rY   r   r!   rZ   r   r)   r   rO   r
   r   r\   s         r(   serve_startr_      s   \ "7+++
#TBBB5o 5 5 5	
 	
 	
  	6555    #l$9 =C J # F v
KKBBBBCCCMs   AA 
A*)A*builderargsc                    t          | t                    r$t          |          dk    rt          d          | S t          | t                    s t          dt          |            d          t          j        |           }t          |j	                  dk    rt          d          |j	        t          |j	                                                  d                  }t          j        |j                  r.t          |j                  r|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    rA   r   	TypeErrortypeinspect	signature
parameterslistkeysisclass
annotationr   r   )r`   ra   rh   paramapps        r(   ,call_user_app_builder_with_args_if_necessaryrp      s    ';'' 
t99q==4   .. 
)W) ) )
 
 	
 !'**I
9  A%%<
 
 	
  i&:&?&?&A&A!B!B1!EFEu'(( 0-F. . 0 ))$//
'$--Cc;'' 
@3799@ @ @
 
 	

 Jr*   )NNN),rg   loggingtypesr   typingr   r   r   r:   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!   rB   r)   rO   r]   r_   strrp   r3   r*   r(   <module>r      s(           # # # # # # # # # # 



 A A A A A A ' ' ' ' ' ' ! ! ! ! ! ! ; ; ; ; ; ;         
 @ ? ? ? ? ? 5 5 5 5 5 5 5 5 D D D D D D D D , , , , , , 2 2 2 2 2 2 * * * * * *		,	-	-!16t[7H1I	   2 4837>B= =dK/0=dK/0= !t]!:;=
 = = = =B 4837>B) )dK/0)dK/0) !t]!:;)
 ) ) ) )Z 4837>BE EdK/0EdK/0E !t]!:;E
 E E E EP3;,-3
sCx.3 3 3 3 3 3 3r*   