
                            S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKrS rS r\R(                  " \R*                  R,                  5      \R.                   " S S\R0                  5      5       5       r\R(                  " \R*                  R4                  \R*                  R6                  5      \R.                   " S S\5      5       5       rg)z(Vertex AI endpoints raw-predict command.    N)client)base)	constants)endpoint_util)flags)region_util)
exceptions)
console_ioc                     [         R                  " U S[        R                  S9  [         R                  " 5       R                  U 5        [         R                  " 5       R                  U 5        g )Nzto do online raw prediction)prompt_func)r   AddEndpointResourceArgr   PromptForOpRegionGetRawPredictHeadersArgAddToParserGetRawPredictRequestArgparsers    'lib/surface/ai/endpoints/raw_predict.py_AddArgsr   !   sO    #//1
 !--f5!--f5    c                 `   U R                   R                  R                  5       nUR                  5       S   U l        [
        R                  " XR                  S9   U R                  R                  S5      (       a#  [        R                  " U R                  SS SS9nOU R                  R                  S5      n[        R                  " US	9nUR                  X R                  U5      u  pVU R!                  S
5      (       d3  ["        R$                  R&                  R)                  U5         SSS5        g [*        R,                  " UR/                  S5      5      sSSS5        $ ! [0         a.    [2        R4                  " S[6        R8                  " U5      -   5      ef = f! , (       d  f       g= f)z Run Vertex AI online prediction.locationsId)region@   NT)binaryzutf-8)versionformatz=No JSON object could be decoded from the HTTP response body:
)CONCEPTSendpointParseAsDictr   r   AiplatformEndpointOverridesrequest
startswithr
   ReadFromFileOrStdinencoder   EndpointsClient
RawPredicthttp_headersIsSpecifiedsysstdoutbufferwritejsonloadsdecode
ValueErrorcore_exceptionsErrorsix	text_type)argsr   endpoint_refr$   endpoints_client_responses          r   _Runr=   +   sS   ''--/,##%m4$+00M||s##..t||AB/?Mg##G,g--g>"--l<M<M.57KA
 H%%	jjh' NM";ZZ01% NM&  ;!! #:"%--"9#: ; ;;' NMs   CF6$E$$8FF
F-c                   .    \ rS rSrSr\S 5       rS rSrg)r)   I   `  Run Vertex AI online raw prediction.

`{command}` sends a raw prediction request to a Vertex AI endpoint. The
request can be given on the command line or read from a file or stdin.

## EXAMPLES

To predict against an endpoint ``123'' under project ``example'' in region
``us-central1'', reading the request from the command line, run:

  $ {command} 123 --project=example --region=us-central1 --request='{
      "instances": [
        { "values": [1, 2, 3, 4], "key": 1 },
        { "values": [5, 6, 7, 8], "key": 2 }
      ]
    }'

If the request body was in the file ``input.json'', run:

  $ {command} 123 --project=example --region=us-central1 --request=@input.json

To send the image file ``image.jpeg'' and set the *content type*, run:

  $ {command} 123 --project=example --region=us-central1
  --http-headers=Content-Type=image/jpeg --request=@image.jpeg
c                     [        U 5        g N)r   r   s    r   ArgsRawPredict.Argsg   s
    Vr   c                 6    [        U[        R                  5      $ rB   )r=   r   
GA_VERSIONselfr8   s     r   RunRawPredict.Runk   s    i**++r    N)	__name__
__module____qualname____firstlineno____doc__staticmethodrC   rI   __static_attributes__rK   r   r   r)   r)   I   s     6  ,r   r)   c                       \ rS rSrSrS rSrg)RawPredictBetao   r@   c                 6    [        U[        R                  5      $ rB   )r=   r   BETA_VERSIONrG   s     r   rI   RawPredictBeta.Run   s    i,,--r   rK   N)rL   rM   rN   rO   rP   rI   rR   rK   r   r   rT   rT   o   s    6.r   rT   )rP   r0   r,   #googlecloudsdk.api_lib.ai.endpointsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r   r   r   googlecloudsdk.corer	   r4   googlecloudsdk.core.consoler
   r6   r   r=   ReleaseTracksReleaseTrackGAUniverseCompatibleCommandr)   BETAALPHArT   rK   r   r   <module>re      s    /  
 6 ( 3 7 / 5 = 2 
6;< D%%(()!, !,  *!,H D%%**D,=,=,C,CD.Z .  E.r   