
    w                        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                  R6                  5       " S S\
R8                  5      5       5       r\
R0                  \
R2                  " \
R4                  R<                  \
R4                  R>                  5       " S S\5      5       5       r g)z/Vertex AI endpoints stream-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 stream raw prediction)prompt_func)r
   AddEndpointResourceArgr   PromptForOpRegionGetRawPredictHeadersArgAddToParserGetRawPredictRequestArgparsers    .lib/surface/ai/endpoints/stream_raw_predict.py_AddArgsr   #   sO    *// !--f5!--f5    c           	   #   f  #    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       Hl  nU R!                  S
5      (       d+  ["        R$                  R&                  R)                  U5        MD   [*        R,                  " UR/                  S5      5      v   Mn     SSS5        g! [0         a.    [2        R4                  " S[6        R8                  " U5      -   5      ef = f! , (       d  f       g= f7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StreamRawPredict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?   .   sP    ''--/,##%m4$+00M||s##..t||AB/?Mg##G,g--g>$55'' h''

)
jj122 NM(  
##LmmH%&
 	

) NMs7   AF1CF 1'E%F 	F1%8FF  
F.*F1c                   .    \ rS rSrSr\S 5       rS rSrg)r,   N   n  Run Vertex AI online stream raw prediction.

`{command}` sends a stream 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StreamRawPredict.Argsl   s
    Vr   c                 6    [        U[        R                  5      $ rD   )r?   r   
GA_VERSIONselfr;   s     r   RunStreamRawPredict.Runp   s    i**++r    N)	__name__
__module____qualname____firstlineno____doc__staticmethodrE   rK   __static_attributes__rM   r   r   r,   r,   N   s     6  ,r   r,   c                       \ rS rSrSrS rSrg)StreamRawPredictBetat   rB   c                 6    [        U[        R                  5      $ rD   )r?   r   BETA_VERSIONrI   s     r   rK   StreamRawPredictBeta.Run   s    i,,--r   rM   N)rN   rO   rP   rQ   rR   rK   rT   rM   r   r   rV   rV   t   s    6.r   rV   )!rR   
__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?   UniverseCompatibleReleaseTracksReleaseTrackGACommandr,   BETAALPHArV   rM   r   r   <module>rh      s    6 &  '  
 6 ( 3 7 / 5 = 2 
6
@ D%%(()!,t|| !, * !,H D%%**D,=,=,C,CD.+ . E .r   