
    B                         S 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 rS	 r\R                  4S
\4S jjrS rg)z0Library for interacting with the LLM model APIs.    )absolute_import)division)unicode_literals)const)apis)errorsc                  h    [         R                  " [        R                  [        R                  5      $ N)r   GetClientInstancer   LLM_API_NAMELLM_API_VERSION     5lib/googlecloudsdk/api_lib/scc/iac_remediation/llm.py	GetClientr      !    			 2 2E4I4I	JJr   c                  h    [         R                  " [        R                  [        R                  5      $ r
   )r   GetMessagesModuler   r   r   r   r   r   GetMessagesr      r   r   returnc                    [        5       n[        5       nUR                  UR                  UR	                  UR                  U S9/SS9/UR                  [        R                  [        R                  [        R                  [        R                  S9S9SU SU 3S9nUR                  R                  U5      n[        U5        UR                  S	   R                   R"                  S	   R$                  $ )
zMakes a call to the LLM.

Args:
  input_text: string of the prompt to be sent to the LLM
  proj_id: project_id of the LLM enabled project
  model_name: name of the LLM model to be used

Returns:
  LLM response in string
)textuser)partsrole)temperaturetopKtopPmaxOutputTokens)contentsgenerationConfigz	projects/z0/locations/us-central1/publishers/google/models/)-googleCloudAiplatformV1GenerateContentRequestmodelr   )r   r   :AiplatformProjectsLocationsEndpointsGenerateContentRequest-GoogleCloudAiplatformV1GenerateContentRequestGoogleCloudAiplatformV1ContentGoogleCloudAiplatformV1Part'GoogleCloudAiplatformV1GenerationConfigr   TEMPTOPKTOPPMAX_OUTPUT_TOKENSprojects_locations_endpointsGenerateContentValidateLLMResponse
candidatescontentr   r   )
input_textproj_id
model_nameclientmessagesrequestresps          r   MakeLLMCallr9   !   s     ;&](OO4<4j4j55::
:K 	 6  $KK**::::#55	 L  5k 5  y PQ[P\]# P '& 
	,	,	<	<W	E$d			#	#	)	)!	,	1	11r   c                 F   U R                   (       a{  U R                   S   R                  (       a]  U R                   S   R                  R                  (       a5  U R                   S   R                  R                  S   R                  (       d  [        R
                  " 5       eg)z=Validates the LLM response.

Args:
  response: LLM response.
r   N)r0   r1   r   r   r   EmptyLLMResponseError)responses    r   r/   r/   J   st     

  #++  #++11  #++11!499

&
&
(( :r   N)__doc__
__future__r   r   r   *googlecloudsdk.api_lib.scc.iac_remediationr   googlecloudsdk.api_lib.utilr   .googlecloudsdk.command_lib.scc.iac_remediationr   r   r   LLM_DEFAULT_MODEL_NAMEstrr9   r/   r   r   r   <module>rD      sH    7 &  ' < , AKK ++&2 		&2R)r   