o
    Zh	                     @   sN   d dl mZmZmZmZ d dlmZ d dlmZm	Z	m
Z
 G dd deeZdS )    )AnyDictListOptional)
Embeddings)	BaseModel
ConfigDictmodel_validatorc                   @   s   e Zd ZU dZdZee ed< dZee	 ed< dZ
ee ed< i Zee ed< eed< ed	d
Zedd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dS )GPT4AllEmbeddingsa  GPT4All embedding models.

    To use, you should have the gpt4all python package installed

    Example:
        .. code-block:: python

            from langchain_community.embeddings import GPT4AllEmbeddings

            model_name = "all-MiniLM-L6-v2.gguf2.f16.gguf"
            gpt4all_kwargs = {'allow_download': 'True'}
            embeddings = GPT4AllEmbeddings(
                model_name=model_name,
                gpt4all_kwargs=gpt4all_kwargs
            )
    N
model_name	n_threadscpudevicegpt4all_kwargsclient )Zprotected_namespacesbefore)modevaluesreturnc                 C   s`   z$ddl m} |d|d|d|dd|dpi |d< W |S  ty/   td	w )z+Validate that GPT4All library is installed.r   )	Embed4Allr   r   r   )r   r   r   r   r   zuCould not import gpt4all library. Please install the gpt4all library to use this embedding model: pip install gpt4allNr   )Zgpt4allr   getImportError)clsr   r   r   r   ]/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/embeddings/gpt4all.pyvalidate_environment!   s   z&GPT4AllEmbeddings.validate_environmenttextsc                    s     fdd|D }dd |D S )zEmbed a list of documents using GPT4All.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        c                    s   g | ]} j |qS r   )r   Zembed).0textselfr   r   
<listcomp>@   s    z5GPT4AllEmbeddings.embed_documents.<locals>.<listcomp>c                 S   s   g | ]	}t tt|qS r   )listmapfloat)r   er   r   r   r!   A   s    r   )r    r   Z
embeddingsr   r   r   embed_documents6   s   
z!GPT4AllEmbeddings.embed_documentsr   c                 C   s   |  |gd S )zEmbed a query using GPT4All.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )r&   )r    r   r   r   r   embed_queryC   s   	zGPT4AllEmbeddings.embed_query)__name__
__module____qualname____doc__r   r   str__annotations__r   intr   r   dictr   r   Zmodel_configr	   classmethodr   r   r   r$   r&   r'   r   r   r   r   r
      s   
 
r
   N)typingr   r   r   r   Zlangchain_core.embeddingsr   Zpydanticr   r   r	   r
   r   r   r   r   <module>   s    