a
    bg	                     @   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eedddZee eee  dddZeee d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   sf   zFddl m} |f |d|d|dd|dp:i |d< W n ty`   td	Y n0 |S )
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 gpt4all)Zgpt4allr   getImportError)clsr   r   r   r   t/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/embeddings/gpt4all.pyvalidate_environment!   s    
z&GPT4AllEmbeddings.validate_environment)textsr   c                    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>@       z5GPT4AllEmbeddings.embed_documents.<locals>.<listcomp>c                 S   s   g | ]}t tt|qS r   )listmapfloat)r   er   r   r   r!   A   r"   r   )r    r   Z
embeddingsr   r   r   embed_documents6   s    
z!GPT4AllEmbeddings.embed_documents)r   r   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   