
                            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$                  j&                         G d dej(                               Z ej"                  ej$                  j,                  ej$                  j.                         G d de             Zy)z$Vertex AI endpoints predict command.    )absolute_import)division)unicode_literals)client)base)	constants)endpoint_util)endpoints_util)flags)region_utilc                 z    t        j                  | dt        j                         t        j                  |        y )Nzto do online prediction)prompt_func)r   AddEndpointResourceArgr   PromptForOpRegionAddPredictInstanceArgparsers    #lib/surface/ai/endpoints/predict.py_AddArgsr      s/    //1 f%    c                 2   | j                   j                  j                         }|j                         d   | _        t        j                  || j                  d      5  t        j                  |      }t        j                  | j                        }|t        j                  k(  r|j                  ||      }n|j                  ||      }| j!                  d      s$t        j"                  |j$                        | _        |cddd       S # 1 sw Y   yxY w)z Run Vertex AI online prediction.locationsIdT)regionis_prediction)versionformatN)CONCEPTSendpointParseAsDictr   r	   AiplatformEndpointOverridesr   EndpointsClientr
   ReadInstancesFromArgsjson_requestr   
GA_VERSIONPredictPredictBetaIsSpecifiedGetDefaultFormatpredictionsr   )argsr   endpoint_refendpoints_clientinstances_jsonresultss         r   _Runr0   &   s    ''--/,##%m4$+00dkk7--g>#99$:K:KLN)&&& ((~Fg ,,\>JgH%"33G4G4GHdk7 7 7s   B$DDc                   &    e Zd ZdZed        Zd Zy)	PredictGa  Run Vertex AI online prediction.

     `{command}` sends a prediction request to Vertex AI endpoint for the
     given instances. This command will read up to 100 instances, though the
     service itself will accept instances up to the payload limit size
     (currently, 1.5MB).

  ## EXAMPLES

  To 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PredictGa.ArgsL   s
    Vr   c                 6    t        |t        j                        S r5   )r0   r   r%   selfr+   s     r   RunzPredictGa.RunP   s    i**++r   N)__name__
__module____qualname____doc__staticmethodr6   r:    r   r   r2   r2   :   s        ,r   r2   c                       e Zd ZdZd Zy)r'   r3   c                 6    t        |t        j                        S r5   )r0   r   BETA_VERSIONr8   s     r   r:   zPredictBeta.Runf   s    i,,--r   N)r;   r<   r=   r>   r:   r@   r   r   r'   r'   T   s     .r   r'   N)r>   
__future__r   r   r   #googlecloudsdk.api_lib.ai.endpointsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   r   r   r   r0   ReleaseTracksReleaseTrackGACommandr2   BETAALPHAr'   r@   r   r   <module>rN      s    + &  ' 6 ( 3 7 8 / 5&( D%%((), , *,2 D%%**D,=,=,C,CD.) . E.r   