Ë
    µŒjP  ã                   ót   — d dl mZmZmZmZmZ d dlZd dlmZ d dl	m
Z
mZ d dlmZmZ dZdZ G d„ d	ee«      Zy)
é    )ÚAnyÚDictÚListÚMappingÚOptionalN)Ú
Embeddings)Úget_from_dict_or_envÚpre_init)Ú	BaseModelÚ
ConfigDictz#sentence-transformers/clip-ViT-B-32i   c                   ó6  — e Zd ZU dZeZeed<   	 dZe	ed<   	 dZ
eed<   	 dZeed<   	 d	Zee   ed
<   	 d	Zee   ed<   	 eZeed<   	  edd¬«      Zededefd„«       Zedeeef   fd„«       Zdee   deee      fd„Zdee   deee      fd„Zdedee   fd„Z y	)ÚDeepInfraEmbeddingsaÅ  Deep Infra's embedding inference service.

    To use, you should have the
    environment variable ``DEEPINFRA_API_TOKEN`` set with your API token, or pass
    it as a named parameter to the constructor.
    There are multiple embeddings models available,
    see https://deepinfra.com/models?type=embeddings.

    Example:
        .. code-block:: python

            from langchain_community.embeddings import DeepInfraEmbeddings
            deepinfra_emb = DeepInfraEmbeddings(
                model_id="sentence-transformers/clip-ViT-B-32",
                deepinfra_api_token="my-api-key"
            )
            r1 = deepinfra_emb.embed_documents(
                [
                    "Alpha is the first letter of Greek alphabet",
                    "Beta is the second letter of Greek alphabet",
                ]
            )
            r2 = deepinfra_emb.embed_query(
                "What is the second letter of Greek alphabet"
            )

    Úmodel_idFÚ	normalizez	passage: Úembed_instructionzquery: Úquery_instructionNÚmodel_kwargsÚdeepinfra_api_tokenÚ
batch_sizeÚforbid© )ÚextraÚprotected_namespacesÚvaluesÚreturnc                 ó*   — t        |dd«      }||d<   |S )z?Validate that api key and python package exists in environment.r   ÚDEEPINFRA_API_TOKEN)r	   )Úclsr   r   s      úr/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/deepinfra.pyÚvalidate_environmentz(DeepInfraEmbeddings.validate_environment;   s*   € ô 3ØÐ)Ð+@ó
Ðð )<ˆÐ$Ñ%Øˆó    c                 ó   — d| j                   iS )zGet the identifying parameters.r   )r   )Úselfs    r   Ú_identifying_paramsz'DeepInfraEmbeddings._identifying_paramsD   s   € ð ˜DŸM™MÐ*Ð*r!   Úinputc                 ó.  — | j                   xs i }d| j                  › �ddœ}	 t        j                  d| j                  › �||| j
                  dœ|¥¬«      }|j                  dk7  r%t        d	|j                  ›d
|j                  ›�«      ‚	 |j                  «       }|d   }|S # t        j                  j                  $ r}t        d|› �«      ‚d }~ww xY w# t        j                  j                  $ r }t        d|› d|j                  › �«      ‚d }~ww xY w)Nzbearer zapplication/json)ÚAuthorizationzContent-Typez'https://api.deepinfra.com/v1/inference/)Úinputsr   )ÚheadersÚjsonz$Error raised by inference endpoint: éÈ   z)Error raised by inference API HTTP code: z, Ú
embeddingszError raised by inference API: z.
Response: )r   r   ÚrequestsÚpostr   r   Ú
exceptionsÚRequestExceptionÚ
ValueErrorÚstatus_codeÚtextr*   ÚJSONDecodeError)r#   r%   Ú_model_kwargsr)   ÚresÚeÚtr,   s           r   Ú_embedzDeepInfraEmbeddings._embedI   s$  € Ø×)Ñ)Ò/¨Rˆð  ' t×'?Ñ'?Ð&@ÐAØ.ñ
ˆð
	IÜ—-‘-Ø9¸$¿-¹-¸ÐIØØ %°D·N±NÑTÀmÐTôˆCð �?‰?˜cÒ!Ýà—?“? C§H¢Hð.óð ð	Ø—‘“
ˆAØ˜<™ˆJð Ðøô! ×"Ñ"×3Ñ3ò 	IÜÐCÀAÀ3ÐGÓHÐHûð	Iûô ×"Ñ"×2Ñ2ò 	ÜØ1°!°°MÀ#Ç(Á(ÀÐLóð ûð	ús/   ¤4B$ ÂC Â$CÃCÃCÃDÃ4DÄDÚtextsc                 ó  — g }|D �cg c]  }| j                   › |› �‘Œ }}t        dt        |«      | j                  «      D �cg c]  }|||| j                  z    ‘Œ }}|D ]  }|| j	                  |«      z  }Œ |S c c}w c c}w )aQ  Embed documents using a Deep Infra deployed embedding model.
        For larger batches, the input list of texts is chunked into smaller
        batches to avoid exceeding the maximum request size.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        r   )r   ÚrangeÚlenr   r9   )r#   r:   r,   r3   Úinstruction_pairsÚiÚchunksÚchunks           r   Úembed_documentsz#DeepInfraEmbeddings.embed_documentsi   s¥   € ð ˆ
ÙKPÓQÉ5À4 × 6Ñ 6Ð7¸°vÒ>È5ÐÐQô ˜1œcÐ"3Ó4°d·o±oÔFó
áF�ð ˜a ! d§o¡oÑ"5Ò6ØFð 	ð 
ó ˆEØ˜$Ÿ+™+ eÓ,Ñ,‰Jð ð Ðùò Rùò
s   ‡A:ÁA?r3   c                 óP   — | j                   › |› �}| j                  |g«      d   }|S )z®Embed a query using a Deep Infra deployed embedding model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )r   r9   )r#   r3   Úinstruction_pairÚ	embeddings       r   Úembed_queryzDeepInfraEmbeddings.embed_query�   s7   € ð #×4Ñ4Ð5°d°VÐ<ÐØ—K‘KÐ!1Ð 2Ó3°AÑ6ˆ	ØÐr!   )!Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚDEFAULT_MODEL_IDr   ÚstrÚ__annotations__r   Úboolr   r   r   r   Údictr   ÚMAX_BATCH_SIZEr   Úintr   Úmodel_configr
   r   r    Úpropertyr   r   r$   r   Úfloatr9   rB   rF   r   r!   r   r   r      s  … ñð8 %€HˆcÓ$Ø"Ø€IˆtÓØ6Ø(Ð�sÓ(Ø.Ø&Ð�sÓ&Ø.Ø#'€L�(˜4‘.Ó'Ø"Ø)-Ð˜ #™Ó-ðDà$€J�Ó$Ø,á HÀ2ÔF€Làð¨$ð °4ò ó ðð ð+ W¨S°#¨XÑ%6ò +ó ð+ð˜D ™Ið ¨$¨t°E©{Ñ*;ó ð@ T¨#¡Yð °4¸¸U¹Ñ3Dó ð0 ð ¨¨U©ô r!   r   )Útypingr   r   r   r   r   r-   Úlangchain_core.embeddingsr   Úlangchain_core.utilsr	   r
   Úpydanticr   r   rK   rP   r   r   r!   r   Ú<module>rY      s2   ðß 5Õ 5ã Ý 0ß ?ß *à8Ð Ø€ô@˜) Zõ @r!   