
    &`ij                        d dl Z d dlZd dlmZmZmZmZmZmZm	Z	m
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mZmZmZmZ d dlmZ d d	lmZ d d
lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m,Z2m3Z4m5Z5m6Z7m8Z9m:Z;m0Z< d dl=m>Z> de5de?fdZ@dedefdZA G d de          Z3de
eBe(f         dee
ee,e(f                  fdZC G d d          Z:de
deDe/f         de
deEe.f         de.fdZFdS )    N)AnyCallableDictListOptionalSetTupleUnion)FieldDescriptor)Message)cloudpickle)ray_option_utils)	BaseModelFieldNonNegativeFloatNonNegativeIntPositiveFloatPositiveInt	validator)pickle_dumps)resources_from_ray_options)DEFAULT_CONSTRUCTOR_RETRY_COUNT#DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_S%DEFAULT_GRACEFUL_SHUTDOWN_WAIT_LOOP_SDEFAULT_HEALTH_CHECK_PERIOD_SDEFAULT_HEALTH_CHECK_TIMEOUT_SDEFAULT_MAX_ONGOING_REQUESTSMAX_REPLICAS_PER_NODE_MAX_VALUE)DEFAULTDeploymentOptionUpdateType)AggregationFunctionAutoscalingConfigDeploymentModeHTTPOptionsProxyLocationRequestRouterConfig)r"   DeploymentConfigDeploymentLanguageEncodingTypeLoggingConfigReplicaConfigr&   )validate_placement_groupdeployment_languageis_cross_languagec                 V    | t           j        k    r|sdS | t           j        k    r|rdS dS )zGFrom Serve client API's perspective, decide whether pickling is needed.TF)r(   PYTHONJAVA)r-   r.   s     m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/_private/config.py_needs_pickler3   3   s=    0777@Q7t	 2 7	7	7<M	7 tu    protoreturnc                    i }|                                  D ]\  }}|j        t          j        k    rB|j        t          j        k    rd |D             ||j        <   Dt          |          ||j        <   \|j        t          j        k    rt          |          ||j        <   |||j        <   | j	        j
        D ]6}|j        |vr+|j        t          j        k    r|j        s|j        ||j        <   7|S )zRecursively convert a protobuf into a Python dictionary.

    This is an alternative to protobuf's `MessageToDict`. Unlike
    `MessageToDict`, this function doesn't add an extra base64
    encoding to bytes when constructing a json response.
    c                 ,    g | ]}t          |          S  )_proto_to_dict).0vs     r2   
<listcomp>z"_proto_to_dict.<locals>.<listcomp>P   s-     $ $ $*+N1%%$ $ $r4   )
ListFieldslabelr   LABEL_REPEATEDtypeTYPE_MESSAGEnamelistr:   
DESCRIPTORfieldscontaining_oneofdefault_value)r5   datafieldvalues       r2   r:   r:   @   s    D((** % %u;/888 z_999$ $/4$ $ $UZ   $(;;UZ  Z?777-e44D$D !( 3 3Jd""
o:::* ;  %2DKr4   c                      e Zd ZU dZ edej                  Zee	         e
d<    eeej                  Zee
d<    edej                  Zee
d<    edej                  Zee
d	<    eeej                  Zee
d
<    eeej                  Zee
d<    eeej                  Zee
d<    eeej                  Zee
d<    edej                  Zee         e
d<    ee ej                  Z!e e
d<   dZ"e#e
d<   e$j%        Z&ee
d<    edej'                  Z(ee)         e
d<    edej                  Z*ee+         e
d<    ee,ej                  Z-ee
d<    e.            Z/e0e)         e
d<    G d d          Z1 e2d	d          d             Z3 e2dd          d             Z4 e2dd          d             Z5d Z6d  Z7d! Z8e9d"e:fd#            Z;e9d$e<fd%            Z=e9d&             Z>dS )'r'   a  Internal datastructure wrapping config options for a deployment.

    Args:
        num_replicas: The number of processes to start up that
            handles requests to this deployment. Defaults to 1.
        max_ongoing_requests: The maximum number of queries
            that is sent to a replica of this deployment without receiving
            a response. Defaults to 5.
        max_queued_requests: Maximum number of requests to this deployment that will be
            queued at each *caller* (proxy or DeploymentHandle). Once this limit is
            reached, subsequent requests will raise a BackPressureError (for handles) or
            return an HTTP 503 status code (for HTTP requests). Defaults to -1 (no
            limit).
        user_config: Arguments to pass to the reconfigure
            method of the deployment. The reconfigure method is called if
            user_config is not None. Must be JSON-serializable.
        graceful_shutdown_wait_loop_s: Duration
            that deployment replicas wait until there is no more work to
            be done before shutting down.
        graceful_shutdown_timeout_s: Controller waits for this duration
            to forcefully kill the replica for shutdown.
        health_check_period_s: Frequency at which the controller health
            checks replicas.
        health_check_timeout_s: Timeout that the controller waits for a
            response from the replica's health check before marking it
            unhealthy.
        autoscaling_config: Autoscaling configuration.
        logging_config: Configuration for deployment logs.
        user_configured_option_names: The names of options manually
            configured by the user.
        request_router_config: Configuration for deployment request router.
        max_constructor_retry_count: Maximum number of times to retry the
            deployment constructor. Defaults to 20.
       )defaultupdate_typenum_replicasmax_ongoing_requestsmax_queued_requestsNuser_configgraceful_shutdown_timeout_sgraceful_shutdown_wait_loop_shealth_check_period_shealth_check_timeout_sautoscaling_config)default_factoryrO   request_router_configFr.   r-   versionlogging_configmax_constructor_retry_countuser_configured_option_namesc                       e Zd ZdZdZdS )DeploymentConfig.ConfigTN)__name__
__module____qualname__validate_assignmentarbitrary_types_allowedr9   r4   r2   Configra      s        ""&r4   rg   T)alwaysc                     t          |t                    r|S |H	 t          j        |           n2# t          $ r%}t          dt          |           d          d }~ww xY w|S )Nz&user_config is not JSON-serializable: .)
isinstancebytesjsondumps	TypeError
ValueErrorstr)clsr<   es      r2   user_config_json_serializablez.DeploymentConfig.user_config_json_serializable   s}    a 	H=U
1 U U U !S#a&&!S!S!STTTU s   0 
A AAc                     ||S t          |t                    s t          dt          |           d          ddlm}  |di |                                }|S )NzGot invalid type 'z,' for logging_config. Expected a dictionary.r   )r*   r9   )rk   dictro   rA   ray.serve.schemar*   )rr   r<   r*   s      r2   logging_config_validz%DeploymentConfig.logging_config_valid   s    9H!T"" 	)T!WW ) ) )  
 	322222MA##%%r4   c                     t          |t                    st          d          |dk     r|dk    rt          d          |S )Nz'max_queued_requests must be an integer.rM   rR   z@max_queued_requests must be -1 (no limit) or a positive integer.)rk   intro   rp   )rr   r<   s     r2   validate_max_queued_requestsz-DeploymentConfig.validate_max_queued_requests   sQ    !S!! 	GEFFFq55Q"WWR   r4   c                 6    t          | j        | j                  S N)r3   r-   r.   selfs    r2   needs_picklezDeploymentConfig.needs_pickle   s    T5t7MNNNr4   c                    |                                  }|                    d          1|                                 rt          j        |d                   |d<   |                    d          r5| j        j        j        |d         d         d<   t          di |d         |d<   |                    d          r|d                             d          }|R|sd|d         d<   nD|                                 rt          j        |          |d         d<   nt          d|           | j
        j        |d         d	<   t          di |d         |d<   |                    d
          rHd|d
         v r)t          j        |d
         d                   |d
         d<   t          di |d
         |d
<   t!          |d                   |d<   t#          di |S )NrT   rY   policy_serialized_policy_defr[   request_router_kwargsr4   zRNon-empty request_router_kwargs not supportedfor cross-language deployments. Got: _serialized_request_router_clsr]   encodingr_   r9   )rv   getr   r   rn   rY   r   r   AutoscalingConfigProtorp   r[   r   RequestRouterConfigProtoEncodingTypeProtoValueLoggingConfigProtorD   DeploymentConfigProto)r   rI   router_kwargss      r2   to_protozDeploymentConfig.to_proto   s`   yy{{88M"".  "" M&1&7]8K&L&L]#88()) 	
 '.E %&x0( *@ * *+,* *D%& 88+,, 	 !89==>UVVM($ MPD012IJJ&&(( 	 $)-88 01/  %P@MP P   *I ()0 -E - -./- -D() 88$%% 	RT"23335F5L)*:66 6%&z2 &8%Q%Q$?O:P%Q%QD!"/3/00
 0
+, %,,t,,,r4   c                 N    |                                                                  S r}   r   SerializeToStringr~   s    r2   to_proto_byteszDeploymentConfig.to_proto_bytes,      }}00222r4   r5   c                    t          |          }d|v r|d         nt          j        }d|v r|d         nd}t          ||          }d|v r;|d         dk    r*|rt	          j        |j                  |d<   n|j        |d<   nd |d<   d|v r~d|d         v r_|d         d         }|dk    r@|r(t	          j        |j        j                  |d         d<   n!|j        j        |d         d<   ni |d         d<   t          di |d         |d<   d|v r|d         
                    d	          sd |d         d	<   |d         
                    d
          sd |d         d
<   |d         
                    d          sd |d         d<   |d         
                    d          sd |d         d<   |d         
                    d          sd |d         d<   |d         
                    d          st          j        |d         d<   t          di |d         |d<   d|v r|d         dk    rd |d<   d|v rt          |d                   |d<   d|v r3d|d         v r)t          j        |d         d                   |d         d<    | di |S )Nr-   r.   FrT   r4   r[   r   rY   upscale_smoothing_factordownscale_smoothing_factorupscaling_factordownscaling_factortarget_ongoing_requestsaggregation_functionr\    r_   r]   r   r9   )r:   r(   r0   r3   r   loadsrT   r[   r   r&   r   r!   MEANr"   setr   Name)rr   r5   rI   r-   r.   r   r   s          r2   
from_protozDeploymentConfig.from_proto/  s   e$$ %,, &''#* 	 *=)D)DD$%%% 	 %%8:KLLD  M"c)) <*5*;E<M*N*ND''*/*;D''&*]#"d**&$/F*GGG(,-D(E+)% )C//# 	N (-!7M  453  "7M 453  NPD012IJ,? - -./- -D()  4'',-112LMM NIM)*+EF,-112NOO PKO)*+GH,-112DEE FAE)*+=>,-112FGG HCG)*+?@,-112KLL MHL)*+DE,-112HII - (, )** *;)X)XTBV=W)X)XD%&I"$$"&Y)T1136344 4D/0 t##T"23335F5K)*:66 6%&z2 s{{T{{r4   proto_bytesc                 T    t          j        |          }|                     |          S r}   )r   
FromStringr   )rr   r   r5   s      r2   from_proto_bytesz!DeploymentConfig.from_proto_bytesx  s$    %0==~~e$$$r4   c                     |             }t          |                                                                          }|                                D ]/\  }}||vr&t	          d| d| dt          |           d          0d |                                D             }|                                D ]\  }}|                    ||           |S )zCreates a default DeploymentConfig and overrides it with kwargs.

        Ignores any kwargs set to DEFAULT.VALUE.

        Raises:
            TypeError: when a keyword that's not an argument to the class is
                passed in.
        z&Got invalid Deployment config option "z" (with value zO) as keyword argument. All Deployment config options must come from this list: rj   c                 :    i | ]\  }}|t           j        k    ||S r9   )r   VALUE)r;   keyvals      r2   
<dictcomp>z1DeploymentConfig.from_default.<locals>.<dictcomp>  s*    RRRxsCSGM=Q=Q#s=Q=Q=Qr4   )r   rv   keysitemsro   rD   __setattr__)rr   kwargsconfigvalid_config_optionsr   r   s         r2   from_defaultzDeploymentConfig.from_default}  s    "6;;==#5#5#7#788  	 	HC...5S 5 5#&5 5 0115 5 5   / SR6<<>>RRR 	) 	)HCsC((((r4   )?rb   rc   rd   __doc__r   r    LightWeightrP   r   r   __annotations__r   NeedsActorReconfigurerQ   r   rS   rz   rT   r   r   NeedsReconfigurerU   r   r   rV   r   rW   r   r   rX   rY   r"   r&   r[   r.   boolr(   r0   r-   HeavyWeightr\   rq   r]   rv   r   r^   r   r_   r   rg   r   rt   rx   r{   r   r   r   classmethodr   r   rl   r   r   r9   r4   r2   r'   r'   f   sZ        ! !F .3U9E. . .L(>*    ).,.D) ) )+     %u.:         u"<"R  K    5:E3.?5 5 5!1    7<e5.D7 7 7!#3   
 ,15-.?, , ,=    -2E..?- - -M   
 7<e"<"R7 7 7!23    27+.D2 2 2.    $t###  28888"U.:  GXc]   
 &+U.D& & &NHTN   
 05u/.?0 0 0    .1SUU #c(222' ' ' ' ' ' ' ' Y}T***	 	 +*	 Y---  .- Y$T222	 	 32	O O O.- .- .-`3 3 3 F4 F F F [FP %5 % % % [%   [  r4   r'   rQ   rY   c                 <   |t           j        dfv rt          j                    }nut          j                                        d          }t          |t                    r|n|                    d          }|                    |           t          di |}| |fS )aF  Return modified `max_ongoing_requests` and `autoscaling_config`
    for when num_replicas="auto".

    If `autoscaling_config` is unspecified, returns the modified value
    AutoscalingConfig.default().
    If it is specified, the specified fields in `autoscaling_config`
    override that of AutoscalingConfig.default().
    NTexclude_unsetr9   )r   r   r"   rN   rv   rk   update)rQ   rY   default_configs      r2   handle_num_replicas_autor     s     gmT222 /688 +244999MM ,d33=#((t(<< 	
 	0111.@@@@!333r4   c                      e Zd ZdZ	 	 	 	 d!dededededed	eeeee	f                           d
ee         dee
         defdZd Z	 	 	 d"ded	eeeee	f                           d
ee         dee
         fdZe	 	 	 	 	 	 	 d#deeef         deee                  deeeef                  dee         d	eeeee	f                           d
ee         dee
         dee         fd            Zd Zd$dZd$dZedeeef         fd            Zedeeee         ef                  fd            Zedeee                  fd            Zed%dedefd            Zed%dedefd            Zd Z d  Z!dS )&r+   a>  Internal datastructure wrapping config options for a deployment's replicas.

    Provides five main properties (see property docstrings for more info):
        deployment_def: the code, or a reference to the code, that this
            replica should run.
        init_args: the deployment_def's init_args.
        init_kwargs: the deployment_def's init_kwargs.
        ray_actor_options: the Ray actor options to pass into the replica's
            actor.
        resource_dict: contains info on this replica's actor's resource needs.

    Offers a serialized equivalent (e.g. serialized_deployment_def) for
    deployment_def, init_args, and init_kwargs. Deserializes these properties
    when they're first accessed, if they were not passed in directly through
    create().

    Use the classmethod create() to make a ReplicaConfig with the deserialized
    properties.

    Note: overwriting or setting any property after the ReplicaConfig has been
    constructed is currently undefined behavior. The config's fields should not
    be modified externally after it is created.
    NTdeployment_def_nameserialized_deployment_defserialized_init_argsserialized_init_kwargsray_actor_optionsplacement_group_bundlesplacement_group_strategymax_replicas_per_noder   c
                    || _         || _        || _        || _        d| _        d| _        d| _        || _        || _        || _	        || _
        |                                  t          | j                  | _        |	| _        dS )zConstruct a ReplicaConfig with serialized properties.

        All parameters are required. See classmethod create() for defaults.
        N)r   r   r   r   _deployment_def
_init_args_init_kwargsr   r   r   r   	_validater   resource_dictr   )
r   r   r   r   r   r   r   r   r   r   s
             r2   __init__zReplicaConfig.__init__  s      $7  *C&$8!&<#  $  "3'>$(@%%:"
 88NOO(r4   c                     |                                   |                                  |                                  | j        | j        t          d          d S d S )NzVSetting max_replicas_per_node is not allowed when placement_group_bundles is provided.)_validate_ray_actor_options!_validate_placement_group_options_validate_max_replicas_per_noder   r   rp   r~   s    r2   r   zReplicaConfig._validate  sq    ((***..000,,... &2,87   3288r4   c                     || _         || _        || _        || _        |                                  t          | j                   | _        d S r}   )r   r   r   r   r   r   r   )r   r   r   r   r   s        r2   r   zReplicaConfig.update  sM     "3'>$(@%%:"78NOOr4   deployment_def	init_argsinit_kwargsc	           
         t          |          s$t          |t                    st          d          |+t          |t          t
          f          st          d          |$t          |t                    st          d          t          j        |          r"|rt          d          |rt          d          t          |t          t          f          s t          dt          |           d          |d	}|i }|i }|t          |t                    r|}n|j        } | |t          |d
t          |                     t          |d          t          |d          ||||          }	||	_        ||	_        ||	_        |	S )z4Create a ReplicaConfig from deserialized parameters.z8@serve.deployment must be called on a class or function.Nzinit_args must be a tuple.zinit_kwargs must be a dict.z1init_args not supported for function deployments.z3init_kwargs not supported for function deployments.Got invalid type "zQ" for deployment_def. Expected deployment_def to be a class, function, or string.r9   z#Could not serialize the deployment z,Could not serialize the deployment init argsz.Could not serialize the deployment init kwargs)callablerk   rq   ro   tuplerD   rv   inspect
isfunctionrp   r   rA   rb   r   reprr   r   r   )
rr   r   r   r   r   r   r   r   r   r   s
             r2   createzReplicaConfig.create#  s    '' 	X
>30O0O 	XVWWW!Z	E4=%I%I!8999#z+t'D'D#9:::n-- 	X X !TUUU X !VWWW.8S/:: 	.T.%9%9 . . .   IK$ "&.#.. >&4##&4&=#Ld>6J6JLL  $RSS&VWW#$!
 
 "0%)r4   c                 T   t          | j        t                    s%t          dt	          | j                   d          h d}| j        D ]}||vrt          d| d|           t          j        | j        d           | j                            d          d	| j        d<   d S d S )
Nr   z/" for ray_actor_options. Expected a dictionary.>   memorynum_cpusnum_gpus	resourcesruntime_envaccelerator_typezSpecifying 'z8' in ray_actor_options is not allowed. Allowed options: T)
in_optionsr   rM   )	rk   r   rv   ro   rA   rp   r   validate_actor_optionsr   )r   allowed_ray_actor_optionsoptions      r2   r   z)ReplicaConfig._validate_ray_actor_optionsg  s   $0$77 	<T$*@%A%A < < <  	%
 	%
 	%
! , 	 	F666 D6 D D(AD D   7
 	/0FSWXXXX !%%j11912D":... :9r4   r6   c                    | j         d S t          | j         t                    s-t          dt	          | j                    dt
           d          | j         dk     s| j         t
          k    r t          d| j          dt
           d          d S )NzGet invalid type 'zM' for max_replicas_per_node. Expected None or an integer in the range of [1, z].rM   zInvalid max_replicas_per_node z:. Valid values are None or an integer in the range of [1, )r   rk   rz   ro   rA   r   rp   r~   s    r2   r   z-ReplicaConfig._validate_max_replicas_per_node  s    %-F$4c:: 	KT$*D%E%E K K'FK K K   &**),KKKK1K K K'FK K K   LKr4   c                    | j         | j        t          d          | j        :t          | j        | j         pdd           d}| j        d         }|                    dd          }| j                            dd          }||k     rt          | d	| d
| d          |                    dd          }| j                            dd          }||k     rt          | d| d
| d          | j                            di           }|                                D ]A\  }}	|                    |d          }
|
|	k     rt          | d| d|	 d
|
 d| d
          @d S d S )Nz[If `placement_group_strategy` is provided, `placement_group_bundles` must also be provided.PACKdetached)bundlesstrategylifetimezWhen using `placement_group_bundles`, the replica actor will be placed in the first bundle, so the resource requirements for the actor must be a subset of the first bundle.r   CPUr   z `num_cpus` for the actor is z, but the bundle only has z `CPU` specified.GPUr   z `num_gpus` for the actor is z `GPU` specified.r   z `z` requirement for the actor is z` specified.)r   r   rp   r,   r   r   r   )r   resource_error_prefixfirst_bundle
bundle_cpureplica_actor_num_cpus
bundle_gpureplica_actor_num_gpusreplica_actor_resourcesactor_resourceactor_valuebundle_values              r2   r   z/ReplicaConfig._validate_placement_group_options  sE   (4+3 G  
 '3$46@&#    "  7:L &))%33J%)%;%?%?
A%N%N"222 , 5 5-5 5!5 5 5   &))%33J%)%;%?%?
A%N%N"222 , 5 5-5 5!5 5 5   '+&<&@&@b&Q&Q#/F/L/L/N/N  ++//BB+--$0 L LN L L,7L L+L L/=L L L   .M 43H r4   c                     | j         F| j        rt          j        | j                  | _         n | j                            d          | _         | j         S )aD  The code, or a reference to the code, that this replica runs.

        For Python replicas, this can be one of the following:
            - Function (Callable)
            - Class (Callable)
            - Import path (str)

        For Java replicas, this can be one of the following:
            - Class path (str)
        Nzutf-8)r   )r   r   r   r   r   decoder~   s    r2   r   zReplicaConfig.deployment_def  s`     '  '2'89W'X'X$$'+'E'L'L$ (M ( ($ ##r4   c                     | j         2| j        rt          j        | j                  | _         n| j        | _         | j         S )zThe init_args for a Python class.

        This property is only meaningful if deployment_def is a Python class.
        Otherwise, it is None.
        )r   r   r   r   r   r~   s    r2   r   zReplicaConfig.init_args  s@     ?"  <"-"3D4M"N"N"&";r4   c                 Z    | j         t          j        | j                  | _         | j         S )zThe init_kwargs for a Python class.

        This property is only meaningful if deployment_def is a Python class.
        Otherwise, it is None.
        )r   r   r   r   r~   s    r2   r   zReplicaConfig.init_kwargs  s,     $ + 1$2M N ND  r4   r5   c                 :   t          |j        |j        |j        dk    r|j        nd |j        dk    r|j        nd t          j        |j                  |j        rt          j        |j                  nd |j	        dk    r|j	        nd |j
        r|j
        nd |	  	        S )Nr4   r   )r+   r   r   r   r   rm   r   r   r   r   r   )rr   r5   r   s      r2   r   zReplicaConfig.from_proto   s    % $#55EOO4!&!2c!9!9EtJu.//,DJu4555-33 **+0+FPE''D
 
 	
r4   r   c                 V    t          j        |          }|                     ||          S r}   )ReplicaConfigProtor   r   )rr   r   r   r5   s       r2   r   zReplicaConfig.from_proto_bytes  s&    "-k::~~e\222r4   c           
          t          | j        | j        | j        | j        t          j        | j                  | j        t          j        | j                  nd| j	        | j
        | j
        nd          S )Nr   r   )r   r   r   r   r   r   r   r   )r  r   r   r   r   rm   rn   r   r   r   r   r~   s    r2   r   zReplicaConfig.to_proto  s    ! $ 89/3"j)?@@+7 %)Jt/K$L$L$L%)%B)5 #'"<"<
 
 
 	
r4   c                 N    |                                                                  S r}   r   r~   s    r2   r   zReplicaConfig.to_proto_bytes'  r   r4   )NNNT)NNN)NNNNNNN)r6   N)T)"rb   rc   rd   r   rq   rl   r   r   r   floatrz   r   r   r   rv   r   r   r
   r   r	   r   r   r   r   r   propertyr   r   r   r  r   r   r   r   r9   r4   r2   r+   r+     sk        > EI26/3!+) +) +) $)+) $	+)
 !&+)  +) "*$tCJ/?*@!A+) #+3-+)  (}+) +) +) +) +)Z  " EI26/3P PP "*$tCJ/?*@!AP #+3-	P
  (}P P P P$  +/04,0DH26/3-1A Ahm,A E#J'A d38n-	A
 $D>A "*$tCJ/?*@!AA #+3-A  (}A &c]A A A [AF3 3 3>   &3 3 3 3j $hm 4 $ $ $ X$* 8E%*e*;$<=    X 
!XeCj1 
! 
! 
! X
! 
 
1 
 
 
 
 [
" 3 35 3 3 3 3 [3
 
 
 3 3 3 3 3r4   r+   proxy_locationhttp_optionsc                    |d}t                      }nt          |t                    rd|v }t          di |}n]t          |t                     r#d}t          di |                    d          }n%t          dt	          |          j         d          | |st          j        |_        nt          j
        |           |_        |S )	a  Prepare `HTTPOptions` with a resolved `location` based on `proxy_location` and `http_options`.

    Precedence:
    - If `proxy_location` is provided, it overrides any `location` in `http_options`.
    - Else if `http_options` specifies a `location` explicitly (HTTPOptions(...) or dict with 'location'), keep it.
    - Else (no `proxy_location` and no explicit `location`) set `location` to `DeploymentMode.EveryNode`.
      A bare `HTTPOptions()` counts as an explicit default (`HeadOnly`).

    Args:
        proxy_location: Optional ProxyLocation (or its string representation).
        http_options: Optional HTTPOptions instance or dict. If None, a new HTTPOptions() is created.

    Returns:
        HTTPOptions: New instance with resolved location.

    Note:
        1. Default ProxyLocation (when unspecified) resolves to DeploymentMode.EveryNode.
        2. Default HTTPOptions() location is DeploymentMode.HeadOnly.
        3. `HTTPOptions` is used in `imperative` mode (Python API) cluster set-up.
            `Declarative` mode (CLI / REST) uses `HTTPOptionsSchema`.

    Raises:
        ValueError: If http_options is not None, dict, or HTTPOptions.
    NFlocationTr   z#Unexpected type for http_options: ``r9   )r$   rk   rv   rp   rA   rb   r#   	EveryNoder  r%   _to_deployment_mode)r
  r  location_set_explicitlys      r2   prepare_imperative_http_optionsr  +  s    8 "'"}}	L$	'	' 

","<"22\22	L+	.	. 
"&"KK\%6%6T%6%J%JKKP$|2D2D2MPPP
 
 	
 & 	=$2$<L! - A. Q Qr4   )Gr   rm   typingr   r   r   r   r   r   r	   r
   google.protobuf.descriptorr   google.protobuf.messager   rayr   ray._commonr   ray._common.pydantic_compatr   r   r   r   r   r   r   ray._common.serializationr   ray._common.utilsr   ray.serve._private.constantsr   r   r   r   r   r   r   ray.serve._private.utilsr   r    ray.serve.configr!   r"   r#   r$   r%   r&   ray.serve.generated.serve_pb2r   r'   r   r(   r)   r   r*   r   r+   r  r   ray.util.placement_groupr,   r   r3   r:   rz   r   rq   rv   r  r9   r4   r2   <module>r      s     I I I I I I I I I I I I I I I I I I I I 6 6 6 6 6 6 + + + + + +       ( ( ( ( ( (                  3 2 2 2 2 2 8 8 8 8 8 8                  I H H H H H H H                                 > = = = = =
'9 
d 
 
 
 
#' #d # # # #Lt t t t ty t t tn	4W-4 t->'G!HI4 4 4 4@k3 k3 k3 k3 k3 k3 k3 k3\1$]231dK/01 1 1 1 1 1 1r4   