
    Ng                     h    d dl mZmZmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ  G d dee          ZdS )    )AnyListOptional)
Embeddings)	BaseModel
ConfigDictFieldmodel_validator)Selfc                      e Zd ZU dZdZeed<   eed<    edd          Z	e
ed<   	  edd	          Ze
ed	<   	  edd
          Ze
ed
<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zee
         ed<   	  edd          Zee
         ed<   	  edd          Zee
         ed<   	  edd          Zeed<   	  edd          Zee         ed<   	  edd          Z ed          defd            Zdee         deee                  fdZdedee         fd Z dS )!LlamaCppEmbeddingsa  llama.cpp embedding models.

    To use, you should have the llama-cpp-python library installed, and provide the
    path to the Llama model as a named parameter to the constructor.
    Check out: https://github.com/abetlen/llama-cpp-python

    Example:
        .. code-block:: python

            from langchain_community.embeddings import LlamaCppEmbeddings
            llama = LlamaCppEmbeddings(model_path="/path/to/model.bin")
    Nclient
model_pathi   n_ctx)aliasn_partsseedFf16_kv
logits_all
vocab_only	use_mlock	n_threadsn_batchn_gpu_layersTverbosedeviceforbid )extraprotected_namespacesafter)modereturnc                 
     j         }g d} fd|D             } j        
 j        |d<   	 ddlm}  ||fddi| _        n?# t
          $ r t          d	          t          $ r}t          d
| d|           d}~ww xY w S )z4Validate that llama-cpp-python library is installed.)r   r   r   r   r   r   r   r   r   r   r   c                 2    i | ]}|t          |          S r   )getattr).0kselfs     c/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/llamacpp.py
<dictcomp>z;LlamaCppEmbeddings.validate_environment.<locals>.<dictcomp>V   s%    GGG74++GGG    Nr   r   )Llama	embeddingTzCould not import llama-cpp-python library. Please install the llama-cpp-python library to use this embedding model: pip install llama-cpp-pythonz&Could not load Llama model from path: z. Received error )r   r   	llama_cppr.   r   ImportError	Exception
ValueError)r*   r   model_param_namesmodel_paramsr.   es   `     r+   validate_environmentz'LlamaCppEmbeddings.validate_environmentE   s
    _

 
 
 HGGG5FGGG(+/+<L(	''''''%
KKdKlKKDKK 	 	 	I  
  	 	 	& & &"#& &  	 s   A "B &A;;B textsc                 Z    | j                             |          }d |d         D             S )zEmbed a list of documents using the Llama model.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        c           	      ^    g | ]*}t          t          t          |d                              +S )r/   )listmapfloat)r(   r6   s     r+   
<listcomp>z6LlamaCppEmbeddings.embed_documents.<locals>.<listcomp>w   s.    MMMQS+//00MMMr-   data)r   create_embedding)r*   r8   
embeddingss      r+   embed_documentsz"LlamaCppEmbeddings.embed_documentsm   s2     [11%88
MM*V:LMMMMr-   textc                 z    | j                             |          }t          t          t          |                    S )zEmbed a query using the Llama model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        )r   embedr;   r<   r=   )r*   rC   r/   s      r+   embed_queryzLlamaCppEmbeddings.embed_queryy   s1     K%%d++	Cy))***r-   )!__name__
__module____qualname____doc__r   r   __annotations__strr	   r   intr   r   r   boolr   r   r   r   r   r   r   r   r   r   model_configr
   r   r7   r   r=   rB   rF   r   r-   r+   r   r      s          FCOOOs'***E3***59---GS---? b'''D#'''-5h///FD///1uU,777J777@uU,777J777/eE555It555,$uT===Ix}===/ #U3i888GXc]888/ #(%N"C"C"CL(3-CCCFE$i000GT000)!E$h777FHSM7772:  L
 _'"""%d % % % #"%N
NT#Y 
N4U3D 
N 
N 
N 
N
+ 
+U 
+ 
+ 
+ 
+ 
+ 
+r-   r   N)typingr   r   r   langchain_core.embeddingsr   pydanticr   r   r	   r
   typing_extensionsr   r   r   r-   r+   <module>rT      s    & & & & & & & & & & 0 0 0 0 0 0 B B B B B B B B B B B B " " " " " "{+ {+ {+ {+ {+J {+ {+ {+ {+ {+r-   