
    dh                     J   S r SSKJr  SSKJrJrJrJrJr  SSK	J
r
Jr  SSKJrJr  \(       a  SSKJr  SSKJr  SSKJr  S	S
S.S\S\S\\\
\4      S\\/\4   4S jjrSS\SS
4S jjr   SS\\   S\\   S\S   SS
4S jjrS S\\   SS4S jjrS S\S\\   SS4S jjrg
)!zUtilities to init Vertex AI.    )metadata)TYPE_CHECKINGAnyCallableOptionalUnion)AsyncCallbackManagerForLLMRunCallbackManagerForLLMRun)BaseLLMcreate_base_retry_decorator
ClientInfo)CredentialsImage   N)max_retriesrun_managerllmr   r   returnc                \   SSK nUR                  R                  R                  UR                  R                  R                  UR                  R                  R
                  UR                  R                  R                  UR                  R                  R                  /n[        XAUS9nU$ )z0Create a retry decorator for Vertex / Palm LLMs.r   N)error_typesr   r   )	google.api_coreapi_core
exceptionsResourceExhaustedServiceUnavailableAbortedDeadlineExceededGoogleAPIErrorr   )r   r   r   googleerrors	decorators         ^/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/vertexai.pycreate_retry_decoratorr%      s      	""44""55""**""33""11F ,I     minimum_expected_versionc                     [        SU  35      e)zRaise ImportError related to Vertex SDK being not available.

Args:
    minimum_expected_version: The lowest expected version of the SDK.
Raises:
    ImportError: an ImportError that mentions a required version of the SDK.
zePlease, install or upgrade the google-cloud-aiplatform library: pip install google-cloud-aiplatform>=)ImportError)r'   s    r$   raise_vertex_import_errorr*   *   s"     	00H/I	K r&   projectlocationcredentialsr   c                 d     SSK nWR                  U UUS9  g! [         a    [        5          N(f = f)a  Init Vertex AI.

Args:
    project: The default GCP project to use when making Vertex API calls.
    location: The default location to use when making API calls.
    credentials: The default custom
        credentials to use when making API calls. If not provided credentials
        will be ascertained from the environment.

Raises:
    ImportError: If importing vertexai SDK did not succeed.
r   N)r+   r,   r-   )vertexair)   r*   init)r+   r,   r-   r/   s       r$   init_vertexair1   8   s=    "$ MM    $!#$s    //moduler   c                      SSK Jn  [        R                  " S5      nU (       a  U SU  3OUnU" USU 3S9$ ! [         a  n[        S5      UeSnAff = f)	zReturn a custom user agent header.

Args:
    module (Optional[str]):
        Optional. The module for a custom user agent header.
Returns:
    google.api_core.gapic_v1.client_info.ClientInfo
r   r   zPCould not import ClientInfo. Please, install it with pip install google-api-coreN	langchain-z
langchain/)client_library_version
user_agent)$google.api_core.gapic_v1.client_infor   r)   r   version)r2   r   exclangchain_versionr6   s        r$   get_client_infor<   U   s~    C !((5+1
Qvh'7H  5 678   *
 	s   8 
AAApathr   c           
      l    SSK Jn  SSKJn  UR                  US9nU R                  S5      n[        UR                  US   SR                  USS	 5      S
95      n[        U5      S:  a  [        SU  S35      eUR                  " US   R                  5       5      $ ! [         a    [        S5      ef = f)z(Load an image from Google Cloud Storage.r   )storagez5Could not import google-cloud-storage python package.r   )r+   /      N)prefixr   z"Found more than one candidate for !)google.cloudr?   r)   "vertexai.preview.generative_modelsr   Clientsplitlist
list_blobsjoinlen
ValueError
from_bytesdownload_as_bytes)r=   r+   r?   r   
gcs_clientpiecesblobss          r$   load_image_from_gcsrS   p   s    S( 90JZZ_F&&vay&*9M&NOE
5zA~=dV1EFFE!H66899  SQRRSs   B B3)z1.38.0)NNN)N)__doc__	importlibr   typingr   r   r   r   r   langchain_core.callbacksr	   r
   #langchain_core.language_models.llmsr   r   r8   r   google.auth.credentialsr   rF   r   intr%   strr*   r1   r<   rS    r&   r$   <module>r]      s   "  @ @ U?38  		  +-EEF	 seSj0 4  ""+/c]sm -( 
	:HSM \ 6:c :HSM :W :r&   