o
    Zh                     @   sV   d dl 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 G dd de
eZdS )    )AnyDictList)
Embeddings)get_from_dict_or_envpre_init)	BaseModel
ConfigDictc                	       s   e Zd ZU dZeed< eed< eed< eddZ			ddeded	ed
df fddZ
eded
efddZdee d
eee  fddZded
ee fddZ  ZS )NLPCloudEmbeddingsa
  NLP Cloud embedding models.

    To use, you should have the nlpcloud python package installed

    Example:
        .. code-block:: python

            from langchain_community.embeddings import NLPCloudEmbeddings

            embeddings = NLPCloudEmbeddings()
    
model_namegpuclient )Zprotected_namespaces%paraphrase-multilingual-mpnet-base-v2FkwargsreturnNc                    s   t  jd||d| d S )N)r   r   r   )super__init__)selfr   r   r   	__class__r   ^/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/embeddings/nlpcloud.pyr      s   zNLPCloudEmbeddings.__init__valuesc                 C   sP   t |dd}zddl}|j|d ||d dd|d	< W |S  ty'   td
w )z?Validate that api key and python package exists in environment.nlpcloud_api_keyZNLPCLOUD_API_KEYr   Nr   r   en)r   langr   zXCould not import nlpcloud python package. Please install it with `pip install nlpcloud`.)r   nlpcloudZClientImportError)clsr   r   r   r   r   r   validate_environment#   s   z'NLPCloudEmbeddings.validate_environmenttextsc                 C   s   | j |d S )zEmbed a list of documents using NLP Cloud.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        
embeddingsr   r!   )r   r    r   r   r   embed_documents6   s   
z"NLPCloudEmbeddings.embed_documentstextc                 C   s   | j |gd d S )zEmbed a query using NLP Cloud.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r!   r   r"   )r   r$   r   r   r   embed_queryB   s   	zNLPCloudEmbeddings.embed_query)r   F)__name__
__module____qualname____doc__str__annotations__boolr   r	   Zmodel_configr   r   r   r   r   floatr#   r%   __classcell__r   r   r   r   r
      s*   
 
r
   N)typingr   r   r   Zlangchain_core.embeddingsr   Zlangchain_core.utilsr   r   Zpydanticr   r	   r
   r   r   r   r   <module>   s
    