
                            d 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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&                  j.                  ej&                  j0                         G d de                    Zy)z2Vertex AI endpoints stream direct predict command.    )absolute_import)division)unicode_literals)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 prediction)prompt_func)r   AddEndpointResourceArgr   PromptForOpRegionAddDirectPredictInputsArgparsers    1lib/surface/ai/endpoints/stream_direct_predict.py_AddArgsr      s/    -//
 !!&)    c           	      >   | 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   |j%                  d	i       
      cddd       S # 1 sw Y   yxY w)z.Run Vertex AI online stream direct prediction.locationsIdT)regionis_predictionv1v1beta1formatjsoninputs
parameters)endpointr   r    N)CONCEPTSr!   ParseAsDictr   r	   AiplatformEndpointOverridesr
   ReadInputsFromArgsjson_requestr   
GA_VERSIONr   PredictionStreamerIsSpecifiedr   StreamDirectPredictRelativeNameget)argsversionendpoint_refinputs_jsonstreamers        r   _Runr3   '   s    ''--/,##%m4$+00dkk !33D4E4EFK)&&&$77=h$77	BhH%dk''**,8$??<4 (   s   B*DDc                   &    e Zd ZdZed        Zd Zy)StreamDirectPredictGa  Run Vertex AI online stream direct prediction.

     `{command}` sends a stream direct prediction request to Vertex AI endpoint
     for the given inputs. 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StreamDirectPredictGa.ArgsO   s
    Vr   c                 6    t        |t        j                        S r8   )r3   r   r(   selfr.   s     r   RunzStreamDirectPredictGa.RunS   s    i**++r   N)__name__
__module____qualname____doc__staticmethodr9   r=    r   r   r5   r5   >   s       ,r   r5   c                       e Zd ZdZd Zy)StreamDirectPredictBetar6   c                 6    t        |t        j                        S r8   )r3   r   BETA_VERSIONr;   s     r   r=   zStreamDirectPredictBeta.Runh   s    i,,--r   N)r>   r?   r@   rA   r=   rC   r   r   rE   rE   W   s    .r   rE   N)rA   
__future__r   r   r   #googlecloudsdk.api_lib.ai.endpointsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   r   r   r   r3   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr5   BETAALPHArE   rC   r   r   <module>rS      s    9 &  ' C ( 3 7 8 / 5*. D%%((),DLL , * ,. D%%**D,=,=,C,CD.3 . E .r   