
    7|h                        d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
 d dlmZmZ d dlmZmZ d dlmZmZmZmZmZ  ej.                  e      ZddZ	 	 	 	 	 	 	 	 dd
Z G d d	ee
      Zy)    )annotationsN)AnyCallableDictListOptional)
Embeddings)get_from_dict_or_envpre_init)	BaseModel
ConfigDict)before_sleep_logretryretry_if_exception_typestop_after_attemptwait_exponentialc            
        ddl } d}d}d}d}t        dt        |      t        |||      t	        | j
                  j                  j                        t	        | j
                  j                  j                        z  t	        | j
                  j                  j                        z  t        t        t        j                        	      S )
zKReturns a tenacity retry decorator, preconfigured to handle PaLM exceptionsr   N      <   
   T)
multiplierminmax)reraisestopwaitr   before_sleep)google.api_core.exceptionsr   r   r   r   api_core
exceptionsResourceExhaustedServiceUnavailableGoogleAPIErrorr   loggerloggingWARNING)googler   min_secondsmax_secondsmax_retriess        i/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/embeddings/google_palm.py_create_retry_decoratorr-      s    %JKKK,+V#FOO$>$>$P$PQ%foo&@&@&S&STU%foo&@&@&O&OPQ &fgoo>
 
    GooglePalmEmbeddingsc                >     t               }|d fd       } ||i |S )z*Use tenacity to retry the completion call.c                 <     j                   j                  | i |S )N)clientgenerate_embeddings)argskwargs
embeddingss     r,   _embed_with_retryz+embed_with_retry.<locals>._embed_with_retry0   s!    4z  44dEfEEr.   )r4   r   r5   r   returnr   )r-   )r6   r4   r5   retry_decoratorr7   s   `    r,   embed_with_retryr:   *   s3     ./OF F d-f--r.   c                  z    e Zd ZU dZded<   ded<   dZded<   	 d	Zd
ed<   	  ed      Ze	dd       Z
ddZddZy)r/   zGoogle's PaLM Embeddings APIs.r   r2   zOptional[str]google_api_keyzmodels/embedding-gecko-001str
model_nameFboolshow_progress_bar )protected_namespacesc                    t        |dd      }	 ddlm} |j                  |       ||d<   |S # t        $ r t	        d      w xY w)z(Validate api key, python package exists.r<   GOOGLE_API_KEYr   N)api_keyz4Could not import google.generativeai python package.r2   )r
   google.generativeaigenerativeai	configureImportError)clsvaluesr<   genais       r,   validate_environmentz)GooglePalmEmbeddings.validate_environmentC   s^     .$&6
	V/OONO3 !x  	VTUU	Vs	   . Ac                    | j                   r	 ddlm}  ||d      }n|}|D cg c]  }| j                  |       c}S # t        $ r t        j	                  d       |}Y Aw xY wc c}w )Nr   )tqdmr/   )desczgUnable to show progress bar because tqdm could not be imported. Please install with `pip install tqdm`.)r@   rO   rI   r%   warningembed_query)selftextsrO   iter_texts        r,   embed_documentsz$GooglePalmEmbeddings.embed_documentsT   sp    !!	%U)?@ E3894  &99  >  :s   A  A&  A#"A#c                :    t        | | j                  |      }|d   S )zEmbed query text.	embedding)r:   r>   )rS   rV   rY   s      r,   rR   z GooglePalmEmbeddings.embed_queryd   s    $T4??DA	%%r.   N)rK   r   r8   r   )rT   z	List[str]r8   zList[List[float]])rV   r=   r8   zList[float])__name__
__module____qualname____doc____annotations__r>   r@   r   model_configr   rM   rW   rR   rA   r.   r,   r/   r/   7   sQ    (K!!2J2#t#J26L  : &r.   )r8   zCallable[[Any], Any])r6   r/   r4   r   r5   r   r8   r   )
__future__r   r&   typingr   r   r   r   r   langchain_core.embeddingsr	   langchain_core.utilsr
   r   pydanticr   r   tenacityr   r   r   r   r   	getLoggerrZ   r%   r-   r:   r/   rA   r.   r,   <module>rg      sp    "  6 6 0 ? *  
		8	$,
.$
.-0
.<?
.
.0&9j 0&r.   