
    Ngy                        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dS )    )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dS ) 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)modevaluesr   returnr   c                    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   )clsr!   s     `/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/clova.pyvalidate_environmentz$ClovaEmbeddings.validate_environmentB   s     '< )<>QRR'
 '
"# -B 13L -
 -
()
 1 3EFF
 
x     texts	List[str]List[List[float]]c                d    g }|D ]*}|                     |                     |                     +|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)selfr+   
embeddingstexts       r(   embed_documentszClovaEmbeddings.embed_documentsS   sC     
 	6 	6Dd..t445555r*   r3   List[float]c                ,    |                      |          S )z
        Embed a single query text and return its embedding.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        )r0   )r1   r3   s     r(   embed_queryzClovaEmbeddings.embed_queryb   s     %%%r*   c                   d|i}t          t          | j                                                  t          t          | j                                                  dd}t          t          | j                                                  }t          j        | j         d| j	         d| ||          }|j
        dk    r0|                                }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.
        r3   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_coder;   
ValueErrorr3   )r1   r3   payloadr:   r   responseresponse_datas          r(   r0   zClovaEmbeddings._embed_textn   s*    4. *.41* *  #'47$ $  .
 
 i-->>@@= 884:8888
 
 
 3&&$MMOOM=(([M(<S-S-S$X.{;;Uh.BUUhmUU
 
 	
r*   )r!   r   r"   r   )r+   r,   r"   r-   )r3   r   r"   r5   )__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   model_configr   classmethodr)   r4   r7   r0    r*   r(   r   r      s$         @ 	N      #E####&-11111:37777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   rN   r*   r(   <module>rU      s   " " " " " " 2 2 2 2 2 2 2 2 2 2 2 2 2 2  6 6 6 6 6 6 0 0 0 0 0 0 L L L L L L L L F F F F F F F F F F F F 
=  
}
 }
 }
 }
 }
i }
 }
 
}
 }
 }
r*   