Ë
    µŒjy  ã                  ó¨   — d dl mZ d dlmZmZmZmZmZ d dl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  e
dd	d
¬«       G d„ dee«      «       Zy)é    )Úannotations)ÚAnyÚDictÚListÚOptionalÚcastN)Ú
deprecated)Ú
Embeddings©Úconvert_to_secret_strÚget_from_dict_or_env)Ú	BaseModelÚ
ConfigDictÚ	SecretStrÚmodel_validatorz0.3.4z1.0.0z$langchain_community.ClovaXEmbeddings)ÚsinceÚremovalÚalternative_importc                  ó¶   — e Zd ZU dZdZded<   	 dZded<   	 dZded	<   	 dZded
<   	 dZ	ded<   	  e
d¬«      Z ed¬«      edd„«       «       Zdd„Zdd„Zdd„Zy)ÚClovaEmbeddingsa  
    Clova's embedding service.

    To use this service,

    you should have the following environment variables
    set with your API tokens and application ID,
    or pass them as named parameters to the constructor:

    - ``CLOVA_EMB_API_KEY``: API key for accessing Clova's embedding service.
    - ``CLOVA_EMB_APIGW_API_KEY``: API gateway key for enhanced security.
    - ``CLOVA_EMB_APP_ID``: Application ID for identifying your application.

    Example:
        .. code-block:: python

            from langchain_community.embeddings import ClovaEmbeddings
            embeddings = ClovaEmbeddings(
                clova_emb_api_key='your_clova_emb_api_key',
                clova_emb_apigw_api_key='your_clova_emb_apigw_api_key',
                app_id='your_app_id'
            )

            query_text = "This is a test query."
            query_result = embeddings.embed_query(query_text)

            document_text = "This is a test document."
            document_result = embeddings.embed_documents([document_text])

    zChttps://clovastudio.apigw.ntruss.com/testapp/v1/api-tools/embeddingÚstrÚendpoint_urlzclir-emb-dolphinÚmodelNzOptional[SecretStr]Úclova_emb_api_keyÚclova_emb_apigw_api_keyÚapp_idÚforbid)ÚextraÚbefore)Úmodec                óœ   — t        t        |dd«      «      |d<   t        t        |dd«      «      |d<   t        t        |dd«      «      |d<   |S )z'Validate api key exists in environment.r   ÚCLOVA_EMB_API_KEYr   ÚCLOVA_EMB_APIGW_API_KEYr   ÚCLOVA_EMB_APP_IDr   )ÚclsÚvaluess     ún/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/clova.pyÚvalidate_environmentz$ClovaEmbeddings.validate_environmentB   sk   € ô '<Ü  Ð)<Ð>QÓRó'
ˆÐ"Ñ#ô -BÜ ØÐ1Ð3Lóó-
ˆÐ(Ñ)ô
 1Ü  ¨Ð3EÓFó
ˆˆxÑð ˆó    c                óX   — g }|D ]"  }|j                  | j                  |«      «       Œ$ |S )zÇ
        Embed a list of texts and return their embeddings.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        )ÚappendÚ_embed_text)ÚselfÚtextsÚ
embeddingsÚtexts       r'   Úembed_documentszClovaEmbeddings.embed_documentsS   s2   € ð ˆ
ÛˆDØ×Ñ˜d×.Ñ.¨tÓ4Õ5ð àÐr)   c                ó$   — | j                  |«      S )z°
        Embed a single query text and return its embedding.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        )r,   )r-   r0   s     r'   Úembed_queryzClovaEmbeddings.embed_queryb   s   € ð ×Ñ Ó%Ð%r)   c                ó  — d|i}t        t        | j                  «      j                  «       t        t        | j                  «      j                  «       ddœ}t        t        | j
                  «      j                  «       }t        j                  | j                  › d| j                  › d|› �||¬«      }|j                  dk(  r#|j                  «       }d|v rd|d   v r|d   d   S t        d	|j                  › d
|j                  › �«      ‚)zT
        Internal method to call the embedding API and handle the response.
        r0   zapplication/json)zX-NCP-CLOVASTUDIO-API-KEYzX-NCP-APIGW-API-KEYzContent-TypeÚ/)ÚheadersÚjsonéÈ   ÚresultÚ	embeddingzAPI request failed with status z: )r   r   r   Úget_secret_valuer   r   ÚrequestsÚpostr   r   Ústatus_coder7   Ú
ValueErrorr0   )r-   r0   Úpayloadr6   r   ÚresponseÚresponse_datas          r'   r,   zClovaEmbeddings._embed_textn   s  € ð ˜4�.ˆô *.Ü˜4×1Ñ1ó*çÑÓ Ü#'Ü˜4×7Ñ7ó$çÑÓ Ø.ñ
ˆô ”i §¡Ó-×>Ñ>Ó@ˆÜ—=‘=Ø× Ñ Ð!  4§:¡: ,¨a°¨xÐ8ØØô
ˆð ×Ñ 3Ò&Ø$ŸM™M›OˆMØ˜=Ñ(¨[¸MÈ(Ñ<SÑ-SØ$ XÑ.¨{Ñ;Ð;ÜØ-¨h×.BÑ.BÐ-CÀ2ÀhÇmÁmÀ_ÐUó
ð 	
r)   )r&   r   Úreturnr   )r.   z	List[str]rC   zList[List[float]])r0   r   rC   zList[float])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r   r   r   Úmodel_configr   Úclassmethodr(   r1   r3   r,   © r)   r'   r   r      s•   … ñð@ 	Nð �#ó ð Ø#€Eˆ3Ó#Ø&Ø-1ÐÐ*Ó1Ø:Ø37ÐÐ0Ó7Ø0Ø"&€FÐÓ&Ø:áØô€Lñ ˜(Ô#Øòó ó $ðóó
&ô 
r)   r   )Ú
__future__r   Útypingr   r   r   r   r   r<   Úlangchain_core._api.deprecationr	   Úlangchain_core.embeddingsr
   Úlangchain_core.utilsr   r   Úpydanticr   r   r   r   r   rK   r)   r'   Ú<module>rR      sN   ðÝ "ç 2Õ 2ã Ý 6Ý 0ß Lß FÓ Fñ Ø
ØØ=ôô
}
�i ó }
óñ
}
r)   