
    ~
i                         d dl Z d dlmZmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZmZmZ  G d de	e          ZdS )	    N)AnyDictListLiteralOptionalType)
Embeddings)run_in_executor)convert_to_secret_strget_from_dict_or_env)	BaseModelField	SecretStrmodel_validatorc                      e Zd ZU dZ edd          Zee         ed<   	  edd          Z	ee         ed<   	 dZ
ed	         ed
<   	 dZeed<   	 dZeed<   	  edd          Zeed<   	  edd          Zee         ed<   	  ed          dedefd            Zdedee         fdZdee         deee                  fdZdedee         fdZdee         deee                  fdZdedee         fdZdS )HunyuanEmbeddingszTencent Hunyuan embedding models API by Tencent.

    For more information, see https://cloud.tencent.com/document/product/1729
    	secret_idN)aliasdefaulthunyuan_secret_id
secret_keyhunyuan_secret_keyap-guangzhou)r   z
ap-beijingregioni   embedding_ctx_lengthFshow_progress_barT)r   excludeclientrequest_clsbefore)modevaluesreturnc                    t          t          |dd                    |d<   t          t          |dd                    |d<   	 ddlm} ddlm} ddlm} dd	lm	} n# t          $ r t          d
          w xY w |            }d|j        _         ||d                                         |d                                                   }||d<    |||d         |          |d<   |S )z?Validate that api key and python package exists in environment.r   HUNYUAN_SECRET_IDr   HUNYUAN_SECRET_KEYr   )
Credential)ClientProfile)HunyuanClient)GetEmbeddingRequestz{Could not import tencentcloud sdk python package. Please install it with `pip install "tencentcloud-sdk-python>=3.0.1139"`.   r   r   r   )r   r   tencentcloud.common.credentialr'   *tencentcloud.common.profile.client_profiler(   -tencentcloud.hunyuan.v20230901.hunyuan_clientr)   %tencentcloud.hunyuan.v20230901.modelsr*   ImportErrorhttpProfilepre_conn_pool_sizeget_secret_value)clsr"   r'   r(   r)   r*   client_profile
credentials           C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain_community/embeddings/hunyuan.pyvalidate_environmentz&HunyuanEmbeddings.validate_environment    s`    '< ## '
 '
"# (= $$ (
 (
#$		AAAAAAPPPPPPSSSSSSQQQQQQQ 	 	 	J  	 '89"5Z&'88::'(99;;
 


 !4}(=VH5E~VVxs   A A7textc                    | j         t          d          |                                  }||_        | j                            |          }t          j        |                                          }|                    d          }|st          d          |d                             d          }|st          d          |S )Nz!Request class is not initialized.Dataz,Occur hunyuan embedding error: Data is emptyr   	Embeddingz1Occur hunyuan embedding error: Embedding is empty)
r   AssertionErrorInputr   GetEmbeddingjsonloadsto_json_stringgetRuntimeError)selfr9   requestresponse	_responsedata	embeddings          r7   _embed_textzHunyuanEmbeddings._embed_textJ   s    # !DEEE""$$;++G44$(Jx/F/F/H/H$I$I	/8}}V/D/D 	OMNNNGKK,,	 	TRSSS    textsc                     g }| j         r8	 ddlm} n"# t          $ r}t          d          |d}~ww xY w ||d          }n|}|D ]*}|                    |                     |                     +|S )zEmbed search docs.r   )tqdmzPackage tqdm must be installed if show_progress_bar=True. Please install with 'pip install tqdm' or set show_progress_bar=False.NzHunyuan Embedding)iterabledesc)r   rO   r0   appendembed_query)rE   rM   
embeddingsrO   e_iterr9   s          r7   embed_documentsz!HunyuanEmbeddings.embed_documents^   s    
! 	%%%%%%%   !/  	 D%.ABBBEEE 	6 	6Dd..t445555s    
1,1c                 ,    |                      |          S )zEmbed query text.)rK   rE   r9   s     r7   rS   zHunyuanEmbeddings.embed_queryr   s    %%%rL   c                 >   K   t          d| j        |           d{V S )zAsynchronous Embed search docs.N)r
   rW   )rE   rM   s     r7   aembed_documentsz"HunyuanEmbeddings.aembed_documentsv   s-      $T4+?GGGGGGGGGrL   c                 >   K   t          d| j        |           d{V S )zAsynchronous Embed query text.N)r
   rS   rY   s     r7   aembed_queryzHunyuanEmbeddings.aembed_queryz   s-      $T4+;TBBBBBBBBBrL   )__name__
__module____qualname____doc__r   r   r   r   __annotations__r   r   r   r   intr   boolr   r   r   r   r   r   r8   strr   floatrK   rW   rS   r[   r]    rL   r7   r   r   
   s         
 .3Ud-S-S-Sx	*SSS.3e,PT.U.U.U+UUU4BFG01BBB( $#$$$S#t###=%d333FC333""'%d"C"C"CK$CCC0_(###'$ '4 ' ' ' $#'R U    (T#Y 4U3D    (& &U & & & &HDI H$tE{:K H H H HCs CtE{ C C C C C CrL   r   )r@   typingr   r   r   r   r   r   langchain_core.embeddingsr	   langchain_core.runnables.configr
   langchain_core.utilsr   r   pydanticr   r   r   r   r   rg   rL   r7   <module>rm      s     ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 0 0 0 0 0 0 ; ; ; ; ; ; L L L L L L L L A A A A A A A A A A A ArC rC rC rC rC
I rC rC rC rC rCrL   