
                            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 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 ddl
mZ d Zd Ze	j$                   e	j&                  e	j(                  j*                         G d de	j,                                      Ze	j$                   e	j&                  e	j(                  j0                  e	j(                  j2                         G d de                    Zy)z6Vertex AI endpoints stream direct raw predict command.    )absolute_import)division)unicode_literalsN)prediction_streamer)base)	constants)endpoint_util)endpoints_util)flags)region_utilc                 z    t        j                  | dt        j                         t        j                  |        y )Nz)to do online stream direct raw prediction)prompt_func)r   AddEndpointResourceArgr   PromptForOpRegionAddDirectRawPredictInputArgparsers    5lib/surface/ai/endpoints/stream_direct_raw_predict.py_AddArgsr       s/    1//
 ##F+    c              #     K   | j                   j                  j                         }|j                         d   | _        t        j                  || j                  d      5  t        j                  | j                        }|t        j                  k(  rt        j                  d      }nt        j                  d      }| j                  d      sd| _        |j!                  |j#                         |d   |d	   
      D ]*  }t%        j&                  |j(                        |_        | , 	 ddd       y# 1 sw Y   yxY ww)z2Run Vertex AI online stream direct raw prediction.locationsIdT)regionis_predictionv1v1beta1formatjsonmethod_nameinput)endpointr   r    N)CONCEPTSr!   ParseAsDictr   r	   AiplatformEndpointOverridesr
   ReadInputFromArgsjson_requestr   
GA_VERSIONr   PredictionStreamerIsSpecifiedr   StreamDirectRawPredictRelativeNamebase64	b64decodeoutput)argsversionendpoint_ref
input_jsonstreamerresps         r   _Runr6   )   s	    ''--/,##%m4$+00dkk  11$2C2CDJ)&&&$77=h$77	BhH%dk//**,}-! 0 
 $$T[[1dkj  s   AE!CD6-	E6D?;Ec                   &    e Zd ZdZed        Zd Zy)StreamDirectRawPredictGaa  Run Vertex AI online stream direct raw prediction.

     `{command}` sends a stream direct raw prediction request to Vertex AI
     endpoint for the given input. The request limit is 10MB.

  ## EXAMPLES

  To stream direct predict against an endpoint ``123'' under project ``example''
  in region ``us-central1'', run:

    $ {command} 123 --project=example --region=us-central1
    --json-request=input.json
  c                     t        |        y N)r   r   s    r   ArgszStreamDirectRawPredictGa.ArgsS   s
    Vr   c                 6    t        |t        j                        S r:   )r6   r   r(   selfr0   s     r   RunzStreamDirectRawPredictGa.RunW   s    i**++r   N)__name__
__module____qualname____doc__staticmethodr;   r?    r   r   r8   r8   B   s       ,r   r8   c                       e Zd ZdZd Zy)StreamDirectRawPredictBetaa  Run Vertex AI online stream direct raw prediction.

     `{command}` sends a stream direct raw prediction request to Vertex AI
     endpoint for the given input. The request limit is 10MB.

  ## EXAMPLES

  To stream direct raw predict against an endpoint ``123'' under project
  ``example'' in region ``us-central1'', run:

    $ {command} 123 --project=example --region=us-central1
    --json-request=input.json
  c                 6    t        |t        j                        S r:   )r6   r   BETA_VERSIONr=   s     r   r?   zStreamDirectRawPredictBeta.Runl   s    i,,--r   N)r@   rA   rB   rC   r?   rE   r   r   rG   rG   [   s    .r   rG   )rC   
__future__r   r   r   r-   #googlecloudsdk.api_lib.ai.endpointsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   r   r   r   r6   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr8   BETAALPHArG   rE   r   r   <module>rU      s    = &  '  C ( 3 7 8 / 5,2 D%%((),t|| , * ,. D%%**D,=,=,C,CD.!9 . E .r   