
    d
                     V    d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ  G d de      Z	y)	zTA library for streaming prediction results from the Vertex AI PredictionService API.    )absolute_import)division)unicode_literalsN)apisc                   "    e Zd ZdZd Zd Zd Zy)PredictionStreamerz(Streams prediction responses using gRPC.c                 :    t        j                  d|      | _        y )N
aiplatform)r   GetGapicClientInstanceclient)selfversions     >lib/googlecloudsdk/api_lib/ai/endpoints/prediction_streamer.py__init__zPredictionStreamer.__init__   s    --lGDDK    c              #     K   | j                   j                  j                  |      }|D ]]  }|j                  j	                  | j                   j                  j
                  j                  t        j                  |                   _ | j                   j                  j
                  j                  t        j                  |            |_	        | j                   j                  j                  t        |g            D ]  }|  yw)a;  Streams prediction results from the Cloud Vertex AI PredictionService API.

    Args:
      endpoint: The name of the endpoint to stream predictions from.
      inputs: The inputs to send to the endpoint.
      parameters: The parameters to send to the endpoint.

    Yields:
      Streamed prediction results.
    )endpointN)r   typesStreamDirectPredictRequestinputsappendTensor	from_jsonjsondumps
parameters
predictionstream_direct_predictiter)r   r   r   r   request
curr_inputr   s          r   StreamDirectPredictz&PredictionStreamer.StreamDirectPredict    s     " kk::H:MG
nn
++


"
"
,
,TZZ
-C
D  **11;;

:G kk,,BBgY
 s   D	Dc              #      K   | j                   j                  j                  |||      }| j                   j                  j	                  t        |g            D ]  }|  yw)a8  Streams prediction results from the Cloud Vertex AI PredictionService API.

    Args:
      endpoint: The name of the endpoint to stream predictions from.
      method_name: The name of the method to call.
      input: The input bytes to send to the endpoint.

    Yields:
      Streamed prediction results.
    )r   method_nameinputN)r   r   StreamDirectRawPredictRequestr   stream_direct_raw_predictr   )r   r   r$   r%   r    r   s         r   StreamDirectRawPredictz)PredictionStreamer.StreamDirectRawPredict?   s`     " kk=={% > G kk,,FFgY
 s   A"A$N)__name__
__module____qualname____doc__r   r"   r(    r   r   r   r      s    0E>r   r   )
r,   
__future__r   r   r   r   googlecloudsdk.api_lib.utilr   objectr   r-   r   r   <module>r1      s&    [ &  '  ,= =r   