
                            d 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	mZ ddl	mZ ddlmZ d Z ej$                  ej&                  j(                         G d dej*                               Z ej$                  ej&                  j.                  ej&                  j0                         G d de             Zy)z$Vertex AI endpoints explain command.    )absolute_import)division)unicode_literals)client)base)	constants)endpoint_util)endpoints_util)flags)region_util)logc                    | j                   j                  j                         }|j                         d   | _        t        j                  || j                  d      5  t        j                  |      }t        j                  | j                        }|t        j                  k(  r|j                  |||       }n|j                  |||       }t!        |d      8t"        j$                  j'                  dj)                  |j*                               | j-                  d      st        j.                  |d	
      | _        |cddd       S # 1 sw Y   yxY w)z!Run Vertex AI online explanation.locationsIdT)regionis_prediction)versiondeployedModelIdNz0Deployed model id to be used for explanation: {}formatexplanations)key_name)CONCEPTSendpointParseAsDictr   r	   AiplatformEndpointOverridesr   EndpointsClientr
   ReadInstancesFromArgsjson_requestr   
GA_VERSIONExplainExplainBetagetattrr   statusPrintr   r   IsSpecifiedGetDefaultFormat)argsr   endpoint_refendpoints_clientinstances_jsonresultss         #lib/surface/ai/endpoints/explain.py_Runr-      s   ''--/,##%m4$+00dkk7--g>#99$:K:KLN)&&& ((~tLg ,,\>4Pgw)*6	jj
<
C
C%%'( H%"33
N,dk%7 7 7s   C"EEc                   &    e Zd ZdZed        Zd Zy)	ExplainGa  Request an online explanation from an Vertex AI endpoint.

     `{command}` sends an explanation request to the Vertex AI endpoint for
     the given instances. This command reads up to 100 instances, though the
     service itself accepts instances up to the payload limit size
     (currently, 1.5MB).

     ## EXAMPLES

     To send an explanation request to the endpoint for the json file,
     input.json, run:

     $ {command} ENDPOINT_ID --region=us-central1 --json-request=input.json
  c                     t        j                  | dt        j                         t        j                  |        t        j
                  d      j                  |        y )Nz to request an online explanation)prompt_funcF)required)r   AddEndpointResourceArgr   PromptForOpRegionAddPredictInstanceArgGetDeployedModelIdAddToParser)parsers    r,   ArgszExplainGa.ArgsI   sH    	  *113 
'	e,88@    c                 6    t        |t        j                        S N)r-   r   r   selfr'   s     r,   RunzExplainGa.RunR   s    i**++r;   N)__name__
__module____qualname____doc__staticmethodr:   r@    r;   r,   r/   r/   8   s"     A A,r;   r/   c                       e Zd ZdZd Zy)r!   r0   c                 6    t        |t        j                        S r=   )r-   r   BETA_VERSIONr>   s     r,   r@   zExplainBeta.Rung   s    i,,--r;   N)rA   rB   rC   rD   r@   rF   r;   r,   r!   r!   V   s    .r;   r!   N)rD   
__future__r   r   r   #googlecloudsdk.api_lib.ai.endpointsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   r   r   googlecloudsdk.corer   r-   ReleaseTracksReleaseTrackGACommandr/   BETAALPHAr!   rF   r;   r,   <module>rU      s    + &  ' 6 ( 3 7 8 / 5 #2 D%%((), , *,: D%%**D,=,=,C,CD.) . E.r;   