
                            d Z ddlmZ ddlmZ ddlmZ ddlZddl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Zd Zd Z e
j0                  e
j2                  j4                         G d de
j6                               Z e
j0                  e
j2                  j:                  e
j2                  j<                         G d de             Zy)z(Vertex AI endpoints raw-predict command.    )absolute_import)division)unicode_literalsN)client)base)	constants)endpoint_util)flags)region_util)
exceptions)
console_ioc                     t        j                  | dt        j                         t        j                         j                  |        t        j                         j                  |        y )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                 L   | j                   j                  j                         }|j                         d   | _        t        j                  || j                        5  | j                  j                  d      r%t        j                  | j                  dd d      }n| j                  j                  d      }t        j                  |	      }|j                  || j                  |      \  }}| j!                  d
      s3t"        j$                  j&                  j)                  |       	 ddd       y	 t+        j,                  |j/                  d            cddd       S # t0        $ r, t3        j4                  dt7        j8                  |      z         w xY w# 1 sw Y   yxY w)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>"--lD<M<M.57KAx
 H%	jjh' NM";ZZ01% NM&  ;!! #:"%--"9#: ; ;;' NMs   CF5#E""5FFF#c                   &    e Zd ZdZed        Zd Zy)r,     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                     t        |        y N)r   r   s    r   ArgszRawPredict.Argsi   s
    Vr   c                 6    t        |t        j                        S rD   )r@   r   
GA_VERSIONselfr;   s     r   RunzRawPredict.Runm   s    i**++r   N)__name__
__module____qualname____doc__staticmethodrE   rJ    r   r   r,   r,   L   s     6  ,r   r,   c                       e Zd ZdZd Zy)RawPredictBetarB   c                 6    t        |t        j                        S rD   )r@   r   BETA_VERSIONrH   s     r   rJ   zRawPredictBeta.Run   s    i,,--r   N)rK   rL   rM   rN   rJ   rP   r   r   rR   rR   q   s    6.r   rR   ) rN   
__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Commandr,   BETAALPHArR   rP   r   r   <module>ra      s    / &  '  
 6 ( 3 7 / 5 = 2 
6;< D%%(()!, !, *!,H D%%**D,=,=,C,CD.Z . E.r   