
    7|h                     p    d Z ddlmZmZmZ ddlZddlmZ ddlm	Z	m
Z
mZ ddlmZmZmZ  G d dee      Zy)	z#This file is for LLMRails Embedding    )DictListOptionalN)
Embeddings)convert_to_secret_strget_from_dict_or_envpre_init)	BaseModel
ConfigDict	SecretStrc                       e Zd ZU dZdZeed<   	 dZee	   ed<   	  e
d      Zeded	efd
       Zdee   d	eee      fdZded	ee   fdZy)LLMRailsEmbeddingsa  LLMRails embedding models.

    To use, you should have the  environment
    variable ``LLM_RAILS_API_KEY`` set with your API key or pass it
    as a named parameter to the constructor.

    Model can be one of ["embedding-english-v1","embedding-multi-v1"]

    Example:
        .. code-block:: python

            from langchain_community.embeddings import LLMRailsEmbeddings
            cohere = LLMRailsEmbeddings(
                model="embedding-english-v1", api_key="my-api-key"
            )
    zembedding-english-v1modelNapi_keyforbid)extravaluesreturnc                 <    t        t        |dd            }||d<   |S )z,Validate that api key exists in environment.r   LLM_RAILS_API_KEY)r   r   )clsr   r   s      g/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/embeddings/llm_rails.pyvalidate_environmentz'LLMRailsEmbeddings.validate_environment'   s,     ( 4GH
 $y    textsc                     t        j                  dd| j                  j                         i|| j                  dd      }|j                         d   D cg c]  }|d   	 c}S c c}w )zCall out to Cohere's embedding endpoint.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        z&https://api.llmrails.com/v1/embeddingsz	X-API-KEY)inputr   <   )headersjsontimeoutdata	embedding)requestspostr   get_secret_valuer   r    )selfr   responseitems       r   embed_documentsz"LLMRailsEmbeddings.embed_documents0   s_     ==4 $,,"?"?"AB 4::6	
 /7mmof.EFd[!FFFs   A%textc                 ,    | j                  |g      d   S )zCall out to Cohere's embedding endpoint.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )r*   )r'   r+   s     r   embed_queryzLLMRailsEmbeddings.embed_queryA   s     ##TF+A..r   )__name__
__module____qualname____doc__r   str__annotations__r   r   r   r   model_configr	   r   r   r   floatr*   r-    r   r   r   r      s    " (E3'#'GXi 'L $ 4  GT#Y G4U3D G"	/ 	/U 	/r   r   )r1   typingr   r   r   r$   langchain_core.embeddingsr   langchain_core.utilsr   r   r	   pydanticr
   r   r   r   r6   r   r   <module>r;      s.    ) ' '  0 V V 5 5?/J ?/r   