
                            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,                  R.                  5       " S S\R0                  5      5       5       r\R(                  \R*                  " \R,                  R4                  \R,                  R6                  5       " S S\5      5       5       rg)z/Vertex AI endpoints stream-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 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)   K   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.Argsi   s
    Vr   c                 6    [        U[        R                  5      $ rA   )r<   r   
GA_VERSIONselfr8   s     r   RunStreamRawPredict.Runm   s    i**++r    N)	__name__
__module____qualname____firstlineno____doc__staticmethodrB   rH   __static_attributes__rJ   r   r   r)   r)   K   s     6  ,r   r)   c                       \ rS rSrSrS rSrg)StreamRawPredictBetaq   r?   c                 6    [        U[        R                  5      $ rA   )r<   r   BETA_VERSIONrF   s     r   rH   StreamRawPredictBeta.Run   s    i,,--r   rJ   N)rK   rL   rM   rN   rO   rH   rQ   rJ   r   r   rS   rS   q   s    6.r   rS   )rO   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<   UniverseCompatibleReleaseTracksReleaseTrackGACommandr)   BETAALPHArS   rJ   r   r   <module>rd      s    6  
 6 ( 3 7 / 5 = 2 
6
@ D%%(()!,t|| !, * !,H D%%**D,=,=,C,CD.+ . E .r   