Ë
    µŒjÄ  ã                   ó„   — 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y)	é    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y)ÚHunyuanEmbeddingsz„Tencent 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	}  |«       }d|j                  _         ||d   j                  «       |d   j                  «       «      }||d<    |||d   |«      |d<   |S # t        $ r t        d
«      ‚w xY w)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           úp/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/hunyuan.pyÚvalidate_environmentz&HunyuanEmbeddings.validate_environment    së   € ô '<Ü ØØ#Ø#óó'
ˆÐ"Ñ#ô (=Ü ØØ$Ø$óó(
ˆÐ#Ñ$ð		ÝAÝPÝSÝQñ '›ˆØ89ˆ×"Ñ"Ô5áØÐ&Ñ'×8Ñ8Ó:ØÐ'Ñ(×9Ñ9Ó;ó
ˆ
ð
 !4ˆˆ}Ñá(¨°V¸HÑ5EÀ~ÓVˆˆxÑØˆøô# ò 	ÜðJóð ð	ús   ´B& Â&B;Útextc                 ó\  — | j                   €t        d«      ‚| j                  «       }||_        | j                  j	                  |«      }t        j                  |j                  «       «      }|j                  d«      }|st        d«      ‚|d   j                  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Ø×"Ñ"Ó$ˆØˆŒà—;‘;×+Ñ+¨GÓ4ˆä$(§J¡J¨x×/FÑ/FÓ/HÓ$Iˆ	à/8¯}©}¸VÓ/DˆÙÜÐMÓNÐNà˜‘G—K‘K Ó,ˆ	ÙÜÐRÓSÐSàÐó    Útextsc                 óÒ   — g }| j                   r	 ddlm}  ||d¬«      }n|}|D ]"  }|j                  | j	                  |«      «       Œ$ |S # t        $ r}t        d«      |‚d}~ww xY w)zEmbed search docs.r   )Útqdmz€Package 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€   € àˆ
Ø×!Ò!ðÝ%ñ  %Ð.AÔB‰EàˆEÛˆDØ×Ñ˜d×.Ñ.¨tÓ4Õ5ð ð Ðøô ò Ü!ð/óð ð	ûðús   �A Á	A&ÁA!Á!A&c                 ó$   — | j                  |«      S )zEmbed query text.)rK   ©rE   r9   s     r7   rS   zHunyuanEmbeddings.embed_queryr   s   € à×Ñ Ó%Ð%rL   c              ƒ   óL   K  — t        d| j                  |«      ƒ d{  –—† S 7 Œ­w)zAsynchronous Embed search docs.N)r
   rW   )rE   rM   s     r7   Úaembed_documentsz"HunyuanEmbeddings.aembed_documentsv   s!   è ø€ ä$ T¨4×+?Ñ+?ÀÓG×GÐGÐGúó   ‚$�"ž$c              ƒ   óL   K  — t        d| j                  |«      ƒ d{  –—† S 7 Œ­w)zAsynchronous Embed query text.N)r
   rS   rY   s     r7   Úaembed_queryzHunyuanEmbeddings.aembed_queryz   s!   è ø€ ä$ T¨4×+;Ñ+;¸TÓB×BÐBÐBúr\   )Ú__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   
   sJ  … ññ
 .3¸ÈdÔ-SÐ�x 	Ñ*ÓSØÙ.3¸,ÐPTÔ.UÐ˜ Ñ+ÓUØØ4B€FˆGÐ0Ñ1ÓBØ(Ø $Ð˜#Ó$ØSØ#Ð�tÓ#Ø=á ¨dÔ3€FˆCÓ3Ø"Ù"'°¸dÔ"C€K�˜$‘ÓCØ0á˜(Ô#ð'¨$ð '°4ò 'ó $ð'ðR ð ¨¨U©ó ð( T¨#¡Yð °4¸¸U¹Ñ3Dó ð(& ð &¨¨U©ó &ðH¨D°©Ið H¸$¸tÀE¹{Ñ:Kó HðC sð C¨t°E©{ô 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   rh   rL   r7   Ú<module>rn      s/   ðÛ ß ;× ;å 0Ý ;ß Lß AÓ AôrC˜
 Iõ rCrL   