o
    Zh                     @   sj   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 deeZdS )	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                   @   s   e Zd ZU dZdZeed< 	 dZee	 ed< 	 e
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dS )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_keyZforbid)extravaluesreturnc                 C   s   t t|dd}||d< |S )z,Validate that api key exists in environment.r   ZLLM_RAILS_API_KEY)r   r   )clsr   r    r   _/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/embeddings/llm_rails.pyvalidate_environment'   s
   
z'LLMRailsEmbeddings.validate_environmenttextsc                 C   s:   t jdd| j i|| jddd}dd | d D S )	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timeoutc                 S   s   g | ]}|d  qS )Z	embeddingr   ).0itemr   r   r   
<listcomp>?   s    z6LLMRailsEmbeddings.embed_documents.<locals>.<listcomp>data)requestspostr   Zget_secret_valuer   r   )selfr   responser   r   r   embed_documents0   s   	
z"LLMRailsEmbeddings.embed_documentstextc                 C   s   |  |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%   r   r   r   embed_queryA   s   	zLLMRailsEmbeddings.embed_query)__name__
__module____qualname____doc__r   str__annotations__r   r   r   r
   Zmodel_configr   r   r   r   floatr$   r&   r   r   r   r   r      s   
 r   )r*   typingr   r   r   r    Zlangchain_core.embeddingsr   Zlangchain_core.utilsr   r   r   Zpydanticr	   r
   r   r   r   r   r   r   <module>   s    