
    O                        S r SSKJr  SSKJr  SSKJ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\
R0                  " \
R2                  R4                  5      \
R6                   " S S\
R8                  5      5       5       r\
R0                  " \
R2                  R<                  \
R2                  R>                  5      \
R6                   " S S\5      5       5       r g)z(Vertex AI endpoints raw-predict command.    )absolute_import)division)unicode_literalsN)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,   L   `  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.Argsj   s
    Vr   c                 6    [        U[        R                  5      $ rE   )r@   r   
GA_VERSIONselfr;   s     r   RunRawPredict.Runn   s    i**++r    N)	__name__
__module____qualname____firstlineno____doc__staticmethodrF   rL   __static_attributes__rN   r   r   r,   r,   L   s     6  ,r   r,   c                       \ rS rSrSrS rSrg)RawPredictBetar   rC   c                 6    [        U[        R                  5      $ rE   )r@   r   BETA_VERSIONrJ   s     r   rL   RawPredictBeta.Run   s    i,,--r   rN   N)rO   rP   rQ   rR   rS   rL   rU   rN   r   r   rW   rW   r   s    6.r   rW   )!rS   
__future__r   r   r   r3   r/   #googlecloudsdk.api_lib.ai.endpointsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   r   googlecloudsdk.corer   r7   googlecloudsdk.core.consoler   r9   r   r@   ReleaseTracksReleaseTrackGAUniverseCompatibleCommandr,   BETAALPHArW   rN   r   r   <module>ri      s    / &  '  
 6 ( 3 7 / 5 = 2 
6;< D%%(()!, !,  *!,H D%%**D,=,=,C,CD.Z .  E.r   