
    &`i\|                        d dl Z d dlZd dlZ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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mZmZmZ d dlmZ d dlmZmZ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* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 d dl6m7Z7m8Z8  ej9        e          Z: ed          Z; ed          Z< G d dee;                   Z= G d dee<                   Z> e8d           G d de>e<                               Z? e8d           G d de>e<                               Z@ e8d           G d de=e;                               ZAdS )    N)AnyAsyncIteratorDict	GeneratorGenericIteratorOptionalTupleTypeVarUnioncast)serve)ObjectRefGenerator)OBJ_REF_NOT_SUPPORTED_ERRORDeploymentHandleSourceDeploymentIDRequestMetadata)SERVE_LOGGER_NAME)CreateRouterCallablecreate_dynamic_handle_optionscreate_init_handle_optionscreate_router)DynamicHandleOptionsBaseInitHandleOptionsBase)ReplicaResult)Router)ServeUsageTag)DEFAULTcalculate_remaining_timeoutget_random_stringinside_ray_client_contextis_running_in_asyncio_loop)RayServeExceptionRequestCancelledError)metrics)DeveloperAPI	PublicAPITRc                      e Zd Zddddddddededee         dee         dee         dee         d	ee	j
                 d
ee         fdZedededefd            Zedededefd            ZdefdZedefd            Zedefd            Zedefd            Zd ZdefdZej        f	 d*dZdee         deeef         deej        j         e!f         fdZ"ej        ej        ej        ej        ej        dde#eef         de#eef         de#eef         de#eef         d e#eef         ddfd!Z$d"eddfd#Z%d$ Z&d% Z'defd&Z(edeeef         dd'fd(            Z)d) Z*dS )+_DeploymentHandleBaseNinit_optionshandle_options_router_create_router_request_counter
_handle_iddeployment_nameapp_namer-   r.   r/   r0   r1   r2   c                   t          ||          | _        || _        |pt                      | _        |pt                      | _        |p|                     ||| j                  | _        || _	        |t          | _        d S || _        d S )N)namer4   )r   deployment_idr-   r   r.   r    	handle_id_create_request_counterrequest_counterr/   r   r0   )	selfr3   r4   r-   r.   r/   r0   r1   r2   s	            d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/handle.py__init__z_DeploymentHandleBase.__init__?   s     *RRR=I=;== 	 $:'8':':/  
43O3Oot~4
 4
 *1!"/D"0D    r8   c                 (    | r
|  d| d| S | d| S )N# )r4   r3   r8   s      r<   _gen_handle_tagz%_DeploymentHandleBase._gen_handle_tag^   s:     	4>>>>9>>>%33	333r>   c                     t          j        ddd                              |                     |||          ||d          S )Nserve_handle_request_counterzGThe number of handle.remote() calls that have been made on this handle.)handle
deploymentrouteapplication)descriptiontag_keys)r8   )rE   rF   rH   )r%   Counterset_default_tagsrB   )clsr4   r3   r8   s       r<   r9   z-_DeploymentHandleBase._create_request_countere   sn     *' F
 
 
 
--o .   .' 
 
	
r>   returnc                 F    | j         dS | j                                         S NF)r/   running_replicas_populatedr;   s    r<   rQ   z0_DeploymentHandleBase.running_replicas_populatedz   s#    <5|66888r>   c                     | j         j        S N)r7   r6   rR   s    r<   r3   z%_DeploymentHandleBase.deployment_name   s    !&&r>   c                     | j         j        S rT   )r7   r4   rR   s    r<   r4   z_DeploymentHandleBase.app_name   s    !**r>   c                     | j         d uS rT   )r/   rR   s    r<   is_initializedz$_DeploymentHandleBase.is_initialized   s    |4''r>   c                    | j         t          d| j         d          t          di |}|                     | j        | j        |          | _         || _        t                              d| j         d| j         dddi	           | j        j	        t          j        k    r1| j        t          k    r#t          j                            d
           dS dS dS )a<  Initialize this handle with arguments.

        A handle can only be initialized once. A handle is implicitly
        initialized when `.options()` or `.remote()` is called. Therefore
        to initialize a handle with custom init options, you must do it
        before calling `.options()` or `.remote()`.
        Nai  Handle has already been initialized. Note that a handle is implicitly initialized when you call `.options()` or `.remote()`. You either tried to call `._init()` twice or called `._init()` after calling `.options()` or `.remote()`. If you want to modify the init options, please do so before calling `.options()` or `.remote()`. This handle was initialized with .)r8   r7   r.   zInitialized DeploymentHandle z for log_to_stderrF)extra1rA   )r/   RuntimeErrorr-   r   r0   r8   r7   loggerinfo_sourcer   PROXY	__class__DeploymentHandler   DEPLOYMENT_HANDLE_API_USEDrecord)r;   kwargsr-   s      r<   _initz_DeploymentHandleBase._init   s    <#=
 )-(9= = =   2;;F;;**n,' + 
 

 )VDNVVASVVV"E* 	 	
 	
 	
 %)?)EEE"2224;;C@@@@@ FE22r>   c                 ,    | j         dS | j         j        S rP   )r-   _run_router_in_separate_looprR   s    r<   #_is_router_running_in_separate_loopz9_DeploymentHandleBase._is_router_running_in_separate_loop   s    $5 ==r>   DeploymentHandle[T]c           
         |                     d          du rt                      rt          d           | j        j        di |}|t
          j        k    r|                     |           | j        s|                                  t          | j
        | j        | j        || j        | j        | j        | j                  S )NstreamTzpStreaming DeploymentHandles are not currently supported when connected to a remote Ray cluster using Ray Client.)_prefer_local_routingr,   rA   )getr!   r]   r.   copy_and_updater   VALUErg   rW   rc   r3   r4   r-   r/   r0   r:   r8   )r;   rn   rf   new_handle_optionss       r<   _optionsz_DeploymentHandleBase._options   s     ::h4'',E,G,G'F  
 AT0@JJ6JJ !GM11JJ-BJCCC" 	JJLLL M*-L.!1~	
 	
 	
 		
r>   argsrf   c                 B   | j         s|                                  t          j        j                            | j        | j                  }| j        	                    |j
        |j        d           | j        t          d           | j        j        |g|R i ||fS )N)rG   rH   )tagszRouter is not initialized)rW   rg   r   _privatedefault_implget_request_metadatar-   r.   r:   incrG   r4   r/   r]   assign_request)r;   rt   rf   metadatas       r<   _remotez_DeploymentHandleBase._remote   s    
 " 	JJLLL>.CCt2
 
 	  !'0  	! 	
 	
 	
 <:;;;*t|*8EdEEEfEExOOr>   method_namemultiplexed_model_idrm   use_new_handle_apirn   r   r   rm   r   rn   c                    t           rT   )NotImplementedErrorr;   r   r   rm   r   rn   s         r<   optionsz_DeploymentHandleBase.options   s
     "!r>   r6   c                 .    |                      |          S )N)r   )r   )r;   r6   s     r<   __getattr__z!_DeploymentHandleBase.__getattr__   s    |||---r>   c                     | j         r_| j                                         }|                                 r|                                 d S t                              d           d S d S )NzSynchronously shutting down a router that's running in the same event loop can only be done best effort. Please use `shutdown_async` instead.)r/   shutdownrj   resultr^   warningr;   shutdown_futures     r<   r   z_DeploymentHandleBase.shutdown   sz    < 		"l3355O7799 &&(((((0    		 		r>   c                    K   | j         rF| j                                         }| j        rt          j        |           d {V  d S | d {V  d S d S rT   )r/   r   rj   asynciowrap_futurer   s     r<   shutdown_asyncz$_DeploymentHandleBase.shutdown_async  s      < 	& %%''  7 &)/:::::::::::%%%%%%%%%%	& 	&r>   c                 0    | j         j         d| j         dS )Nz(deployment='z'))rb   __name__r3   rR   s    r<   __repr__z_DeploymentHandleBase.__repr__  s!    .)TTD<PTTTTr>   z_DeploymentHandleBase[T]c                      | di |S )z<Required for this class's __reduce__ method to be picklable.rA   rA   )rM   rf   s     r<   _deserializez"_DeploymentHandleBase._deserialize  s     s}}V}}r>   c                 J    | j         | j        | j        d}| j        j        |ffS )N)r3   r4   r.   )r3   r4   r.   rb   r   )r;   serialized_constructor_argss     r<   
__reduce__z _DeploymentHandleBase.__reduce__  s6    #3"1'
 '
#
 ~*-H,JJJr>   )rN   rk   )+r   
__module____qualname__strr	   r   r   r   r   r%   rK   r=   staticmethodrB   classmethodr9   boolrQ   propertyr3   r4   rW   rg   rj   r   rq   rs   r
   r   r   
concurrentfuturesFuturer   r}   r   r   r   r   r   r   r   r   rA   r>   r<   r+   r+   >   s        9==A$(9=6:$(1 1 11 1
 451 !!9:1 &!1 !!561 #7?31 SM1 1 1 1> 4# 4 4 4 4 4 \4 

-0
=@
 
 
 [
(9D 9 9 9 9 ' ' ' ' X' +# + + + X+ ( ( ( ( X($A $A $AL>T > > > > %,M
	
 
 
 
:PCjP S#XP 
z!(/9	:	P P P P4 ,3=4;M'.}3:=6=m	" 	" 	" 3<(	" $CL1		"
 dGm$	" "$-0	"  %T7]3	" 
	" 	" 	" 	". .(= . . . .
 
 
& & &U# U U U U $sCx. 5O    [K K K K Kr>   r+   c                       e Zd Z	 ddeej        j        e         ej        e         f         de	de
fdZedefd            Zede
fd            Z	 dd
ee         defdZdefdZd Zede
fd            Zd	S )_DeploymentResponseBaseTreplica_result_futurerequest_metadatarj   c                 L    d| _         || _        d | _        || _        || _        d S rP   )
_cancelled_replica_result_future_replica_result_request_metadatarj   )r;   r   r   rj   s       r<   r=   z _DeploymentResponseBase.__init__!  s1      &;#8<2B3V000r>   rN   c                     | j         j        S rT   )r   
request_idrR   s    r<   r   z"_DeploymentResponseBase.request_id/  s    %00r>   c                     | j         j        S rT   )r   _by_referencerR   s    r<   by_referencez$_DeploymentResponseBase.by_reference3  s    %33r>   N
_timeout_sc                    | j         | j        st          d          	 t          t          j        j        t                   | j                  }|	                    |          | _         nP# t          j        j
        $ r t          d          dt          j        j        $ r t          | j                  dw xY w| j         S )ziSynchronously fetch the replica result.

        The result is cached in `self._replica_result`.
        NdSync methods should not be called from within an `asyncio` event loop. Use `await response` instead.)timeoutz!Timed out resolving to ObjectRef.)r   rj   r]   r   r   r   r   r   r   r   TimeoutErrorCancelledErrorr$   r   )r;   r   sync_futures      r<   _fetch_future_result_syncz1_DeploymentResponseBase._fetch_future_result_sync7  s     '; ":  G #&-m</  (3'9'9*'9'M'M$$%2 R R R"#FGGTQ%4 G G G+DO<<$FG ##s   A
A* *AB7c                    K   | j         c| j        r%t          j        | j                   d{V | _         n7t          t          j        t                   | j                  }| d{V | _         | j         S )zgAsynchronously fetch replica result.

        The result is cached in `self._replica_result`..
        N)r   rj   r   r   r   r   r   r   )r;   async_futures     r<   _fetch_future_result_asyncz2_DeploymentResponseBase._fetch_future_result_asyncU  s       '7 : .5-@/. . ( ( ( ( ( ($$
  $N=143N    .:'9'9'9'9'9'9$##r>   c                 *   | j         rdS d| _         | j                                         | j        s"| j        r| j                                         dS 	 |                                  n# t          $ r Y dS w xY w| j                                         dS )aL  Attempt to cancel the `DeploymentHandle` call.

        This is best effort.

        - If the request hasn't been assigned to a replica, the assignment will be
          cancelled.
        - If the request has been assigned to a replica, `ray.cancel` will be
          called on the object ref, attempting to cancel the request and any downstream
          requests it makes.

        If the request is successfully cancelled, subsequent operations on the ref will
        raise an exception:

            - If the request was cancelled before assignment, they'll raise
              `asyncio.CancelledError` (or a `concurrent.futures.CancelledError` for
              synchronous methods like `.result()`.).
            - If the request was cancelled after assignment, they'll raise
              `ray.exceptions.TaskCancelledError`.
        NT)r   r   cancelrj   r   r   r$   rR   s    r<   r   z_DeploymentResponseBase.cancell  s    ( ? 	F#**,,,7 	 # .$++---F	 **,,,,$ 	 	 	FF	 	##%%%%%s   A) )
A76A7c                     | j         S )zWhether or not the request has been cancelled.

        This is `True` if `.cancel()` is called, but the request may actually have run
        to completion.
        )r   rR   s    r<   	cancelledz!_DeploymentResponseBase.cancelled  s     r>   )TrT   )r   r   r   r   r   r   r   r   r   r   r   r=   r   r   r   r   r	   floatr   r   r   r&   r   rA   r>   r<   r   r      sG        59W W$%m4gn]6SS 
W
 *W .2W W W W 1C 1 1 1 X1 4d 4 4 4 X4 -1$ $"5/$	$ $ $ $<$- $ $ $ $.'& '& '&R 4    \  r>   r   stable)	stabilityc                       e Zd ZdZdeedef         fdZd Zdddde	e
         d	edefd
Zedej        fd            Ze	 	 dde	e
         dedej        fd            ZdS )DeploymentResponsea  A future-like object wrapping the result of a unary deployment handle call.

    From inside a deployment, a `DeploymentResponse` can be awaited to retrieve the
    output of the call without blocking the asyncio event loop.

    From outside a deployment, `.result()` can be used to retrieve the output in a
    blocking manner.

    Example:

    .. code-block:: python

        from ray import serve
        from ray.serve.handle import DeploymentHandle

        @serve.deployment
        class Downstream:
            def say_hi(self, message: str) -> str:
                return f"Hello {message}!"

        @serve.deployment
        class Caller:
            def __init__(self, handle: DeploymentHandle):
                self._downstream_handle = handle

        async def __call__(self, message: str) -> str:
            # Inside a deployment: `await` the result to enable concurrency.
            response = self._downstream_handle.say_hi.remote(message)
            return await response

        app = Caller.bind(Downstream.bind())
        handle: DeploymentHandle = serve.run(app)

        # Outside a deployment: call `.result()` to get output.
        response = handle.remote("world")
        assert response.result() == "Hello world!"

    A `DeploymentResponse` can be passed directly to another `DeploymentHandle` call
    without fetching the result to enable composing multiple deployments together.

    Example:

    .. code-block:: python

        from ray import serve
        from ray.serve.handle import DeploymentHandle

        @serve.deployment
        class Adder:
            def add(self, val: int) -> int:
                return val + 1

        @serve.deployment
        class Caller:
            def __init__(self, handle: DeploymentHandle):
                self._adder_handle = handle

        async def __call__(self, start: int) -> int:
            return await self._adder_handle.add.remote(
                # Pass the response directly to another handle call without awaiting.
                self._adder_handle.add.remote(start)
            )

        app = Caller.bind(Adder.bind())
        handle: DeploymentHandle = serve.run(app)
        assert handle.remote(0).result() == 2
    rN   Nc              #   4  K   	 |                                                                  E d{V }|                                                                E d{V }|S # t          j        $ r* | j        rt          | j                  dt          j        dw xY w)z6Yields the final result of the deployment handle call.N)r   	__await__	get_asyncr   r   r   r$   r   )r;   replica_resultr   s      r<   r   zDeploymentResponse.__await__  s      	7(,(G(G(I(I(S(S(U(UUUUUUUN . 8 8 : : D D F FFFFFFFFM% 	7 	7 	7 7+DO<<$F,$6		7s   AA 9Bc                      t          d          )Na  `DeploymentResponse` is not serializable. If you are passing the `DeploymentResponse` in a nested object (e.g. a list or dictionary) to a downstream deployment handle call, that is no longer supported. Please only pass `DeploymentResponse` objects as top level arguments.)r#   rR   s    r<   r   zDeploymentResponse.__reduce__  s    M
 
 	
r>   F	timeout_s_skip_asyncio_checkr   r   c                    |st                      rt          d          t          j                    }|                     |          }t	          ||t          j                              }|                    |          S )aU  Fetch the result of the handle call synchronously.

        This should *not* be used from within a deployment as it runs in an asyncio
        event loop. For model composition, `await` the response instead.

        If `timeout_s` is provided and the result is not available before the timeout,
        a `TimeoutError` is raised.
        r   r   start_time_scurr_time_s)r"   r]   timer   r   ro   )r;   r   r   r   r   remaining_timeout_ss         r<   r   zDeploymentResponse.result  s     # 	'A'C'C 	6  
 y{{77	BB9l	
 
 
 !!"5666r>   c                    K   t           j                            d           | j        j        st
          |                                  d{V }|                                 d{V S )a  Advanced API to convert the response to a Ray `ObjectRef`.

        This is used to pass the output of a `DeploymentHandle` call to a Ray task or
        actor method call.

        This method is `async def` because it will block until the handle call has been
        assigned to a replica. If there are many requests in flight and all
        replicas' queues are full, this may be a slow operation.
        r\   N)r   (DEPLOYMENT_HANDLE_TO_OBJECT_REF_API_USEDre   r   r   r   r   to_object_ref_asyncr;   r   s     r<   _to_object_refz!DeploymentResponse._to_object_ref  sz       	>EEcJJJ%3 	.--#>>@@@@@@@@#77999999999r>   r   _allow_running_in_asyncio_loopc                 f   t           j                            d           | j        j        st
          |st                      rt          d          t          j                    }| 	                    |          }t          ||t          j                              }|                    |          S )a  Advanced API to convert the response to a Ray `ObjectRef`.

        This is used to pass the output of a `DeploymentHandle` call to a Ray task or
        actor method call.

        This method is a *blocking* call because it will block until the handle call has
        been assigned to a replica. If there are many requests in flight and all
        replicas' queues are full, this may be a slow operation.

        From inside a deployment, `_to_object_ref` should be used instead to avoid
        blocking the asyncio event loop.
        r\   uSync methods should not be called from within an `asyncio` event loop. Use `await response._to_object_ref()` instead.r   )r   )r   r   re   r   r   r   r"   r]   r   r   r   to_object_ref)r;   r   r   r   r   r   s         r<   _to_object_ref_syncz&DeploymentResponse._to_object_ref_sync*  s    & 	>EEcJJJ%3 	.--- 	2L2N2N 	G   y{{77
CC : %	
 
 

 ++6I+JJJr>   rP   )r   r   r   __doc__r   r   r)   r   r   r	   r   r   r   r&   ray	ObjectRefr   r   rA   r>   r<   r   r     s        B BH
79S$\2 
7 
7 
7 
7
 
 
 &*$)	7 7 7 E?7 "	7
 
7 7 7 7: :cm : : : \:&  '+/4'K 'KUO'K )-'K 
	'K 'K 'K \'K 'K 'Kr>   r   c                       e Zd ZdZd Zdee         fdZdefdZde	e         fdZ
defdZdd	d
dee         dedefdZedefd            Ze	 	 ddee         dedefd            ZdS )DeploymentResponseGeneratora5  A future-like object wrapping the result of a streaming deployment handle call.

    This is returned when using `handle.options(stream=True)` and calling a generator
    deployment method.

    `DeploymentResponseGenerator` is both a synchronous and asynchronous iterator.

    When iterating over results from inside a deployment, `async for` should be used to
    avoid blocking the asyncio event loop.

    When iterating over results from outside a deployment, use a standard `for` loop.

    Example:

    .. code-block:: python

        from typing import AsyncGenerator, Generator

        from ray import serve
        from ray.serve.handle import DeploymentHandle

        @serve.deployment
        class Streamer:
            def generate_numbers(self, limit: int) -> Generator[int]:
                for i in range(limit):
                    yield i

        @serve.deployment
        class Caller:
            def __init__(self, handle: DeploymentHandle):
                # Set `stream=True` on the handle to enable streaming calls.
                self._streaming_handle = handle.options(stream=True)

        async def __call__(self, limit: int) -> AsyncIterator[int]:
            gen: DeploymentResponseGenerator = (
                self._streaming_handle.generate_numbers.remote(limit)
            )

            # Inside a deployment: use `async for` to enable concurrency.
            async for i in gen:
                yield i

        app = Caller.bind(Streamer.bind())
        handle: DeploymentHandle = serve.run(app)

        # Outside a deployment: use a standard `for` loop.
        gen: DeploymentResponseGenerator = handle.options(stream=True).remote(10)
        assert [i for i in gen] == list(range(10))

    A `DeploymentResponseGenerator` *cannot* currently be passed to another
    `DeploymentHandle` call.
    c                      t          d          )Nzr`DeploymentResponseGenerator` cannot be awaited directly. Use `async for` or `await response.__anext__() instead`.	TypeErrorrR   s    r<   r   z%DeploymentResponseGenerator.__await__  s    7
 
 	
r>   rN   c                     | S rT   rA   rR   s    r<   	__aiter__z%DeploymentResponseGenerator.__aiter__      r>   c                    K   	 |                                   d {V }|                                 d {V S # t          j        $ r* | j        rt          | j                  d t          j        d w xY wrT   )r   	__anext__r   r   r   r$   r   r   s     r<   r   z%DeploymentResponseGenerator.__anext__  s      	7#'#B#B#D#DDDDDDDN'11333333333% 	7 	7 	7 7+DO<<$F,$6		7s	   38 9A1c                     | S rT   rA   rR   s    r<   __iter__z$DeploymentResponseGenerator.__iter__  r   r>   c                     t                      rt          d          |                                 }|                                S )NzSync methods should not be called from within an `asyncio` event loop. Use `async for` or `await response.__anext__()` instead.)r"   r]   r   __next__r   s     r<   r   z$DeploymentResponseGenerator.__next__  sM    %'' 	Q  
 7799&&(((r>   NFr   r   r   c                     t          d          )a
  Not supported on `DeploymentResponseGenerator`.

        This method exists only for API parity with `DeploymentResponse.result()` to
        aid static typing. A `DeploymentResponseGenerator` is returned when using
        streaming handles (e.g., `handle.options(stream=True)`).

        To consume results, iterate over the generator instead of calling `.result()`:
          - Outside a deployment: use a standard `for` loop
          - Inside a deployment: use `async for`

        Always raises `TypeError`.
        z`DeploymentResponseGenerator` doesn't support `.result()`. Use iteration instead: `for item in response` (outside deployments) or `async for item in response` (inside deployments).r   )r;   r   r   s      r<   r   z"DeploymentResponseGenerator.result  s    $ D
 
 	
r>   c                    K   t           j                            d           | j        j        st
          |                                  d{V }|                                S )a3  Advanced API to convert the generator to a Ray `ObjectRefGenerator`.

        This method is `async def` because it will block until the handle call has been
        assigned to a replica. If there are many requests in flight and all
        replicas' queues are full, this may be a slow operation.
        r\   N)r   r   re   r   r   r   r   to_object_ref_genr   s     r<   _to_object_ref_genz.DeploymentResponseGenerator._to_object_ref_gen  sh       	>EEcJJJ%3 	.--#>>@@@@@@@@//111r>   r   r   c                     t           j                            d           | j        j        st
          |st                      rt          d          |                     |          }|	                                S )a  Advanced API to convert the generator to a Ray `ObjectRefGenerator`.

        This method is a *blocking* call because it will block until the handle call has
        been assigned to a replica. If there are many requests in flight and all
        replicas' queues are full, this may be a slow operation.

        From inside a deployment, `_to_object_ref_gen` should be used instead to avoid
        blocking the asyncio event loop.
        r\   r   )
r   r   re   r   r   r   r"   r]   r   r   )r;   r   r   r   s       r<   _to_object_ref_gen_syncz3DeploymentResponseGenerator._to_object_ref_gen_sync  s      	>EEcJJJ%3 	.--- 	2L2N2N 	G  
 77
CC//111r>   rP   )r   r   r   r   r   r   r)   r   r   r   r   r   r	   r   r   r   r   r&   r   r   r   rA   r>   r<   r   r   U  s`       3 3j
 
 
=+    7 7 7 7 7(1+    )! ) ) ) ) &*$)	
 
 
 E?
 "	

 

 
 
 
0 2*< 2 2 2 \2   '+/42 2UO2 )-2 
	2 2 2 \2 2 2r>   r   c                       e Zd ZdZej        ej        ej        ej        ej        ddeeef         deeef         deeef         deeef         deeef         dd	fd
Z	dee
e         ee         f         fdZdS )rc   al  A handle used to make requests to a deployment at runtime.

    This is primarily used to compose multiple deployments within a single application.
    It can also be used to make calls to the ingress deployment of an application (e.g.,
    for programmatic testing).

    Example:


    .. code-block:: python

        import ray
        from ray import serve
        from ray.serve.handle import DeploymentHandle, DeploymentResponse

        @serve.deployment
        class Downstream:
            def say_hi(self, message: str):
                return f"Hello {message}!"
                self._message = message

        @serve.deployment
        class Ingress:
            def __init__(self, handle: DeploymentHandle):
                self._downstream_handle = handle

            async def __call__(self, name: str) -> str:
                response = self._downstream_handle.say_hi.remote(name)
                return await response

        app = Ingress.bind(Downstream.bind())
        handle: DeploymentHandle = serve.run(app)
        response = handle.remote("world")
        assert response.result() == "Hello world!"
    r~   r   r   rm   r   rn   rN   rk   c                    |t           j        urt          j        d           |t           j        urt          j        d           |                     ||||          S )a(  Set options for this handle and return an updated copy of it.

        Example:

        .. code-block:: python

            response: DeploymentResponse = handle.options(
                method_name="other_method",
                multiplexed_model_id="model:v1",
            ).remote()
        ziSetting `use_new_handle_api` no longer has any effect. This argument will be removed in a future version.z^Modifying `_prefer_local_routing` with `options()` is deprecated. Please use `init()` instead.)r   r   rm   rn   )r   rq   warningswarnrs   r   s         r<   r   zDeploymentHandle.options  s|    ( W]22ME  
 !55M;  
 }}#!5"7	  
 
 	
r>   c                     |                      ||          \  }}| j        j        r$t          |||                                           S t          |||                                           S )a  Issue a remote call to a method of the deployment.

        By default, the result is a `DeploymentResponse` that can be awaited to fetch
        the result of the call or passed to another `.remote()` call to compose multiple
        deployments.

        If `handle.options(stream=True)` is set and a generator method is called, this
        returns a `DeploymentResponseGenerator` instead.

        Example:

        .. code-block:: python

            # Fetch the result directly.
            response = handle.remote()
            result = await response

            # Pass the result to another handle call.
            composed_response = handle2.remote(handle1.remote())
            composed_result = await composed_response

        Args:
            *args: Positional arguments to be serialized and passed to the
                remote method call.
            **kwargs: Keyword arguments to be serialized and passed to the
                remote method call.
        )rj   )r}   r.   rm   r   rj   r   )r;   rt   rf   futurer   s        r<   remotezDeploymentHandle.remoteA  s    > $(<<f#=#=  % 	. 484\4\4^4^    & 484\4\4^4^   r>   N)r   r   r   r   r   rq   r   r   r   r   r   r   r   r   rA   r>   r<   rc   rc     s        " "N ,3=4;M'.}3:=6=m%
 %
 %
 3<(%
 $CL1	%

 dGm$%
 "$-0%
  %T7]3%
 
%
 %
 %
 %
N+	!#&(CC(HH	I+ + + + + +r>   rc   )Br   concurrent.futuresr   loggingr   r   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   ray._rayletr   ray.serve._private.commonr   r   r   r   ray.serve._private.constantsr   ray.serve._private.default_implr   r   r   r   !ray.serve._private.handle_optionsr   r   !ray.serve._private.replica_resultr   ray.serve._private.routerr   ray.serve._private.usager   ray.serve._private.utilsr   r   r    r!   r"   ray.serve.exceptionsr#   r$   ray.utilr%   ray.util.annotationsr&   r'   	getLoggerr^   r(   r)   r+   r   r   r   rc   rA   r>   r<   <module>r     s                                    


       * * * * * *            ; : : : : :                   < ; ; ; ; ; , , , , , , 2 2 2 2 2 2              J I I I I I I I       8 8 8 8 8 8 8 8		,	-	- GCLLGCLL_K _K _K _K _KGAJ _K _K _KD| | | | |gaj | | |~ XrK rK rK rK rK03 rK rK rKj X[2 [2 [2 [2 [2"9!"< [2 [2 [2| Xw w w w w,Q/ w w w w wr>   