Ë
    µŒj—  ã            	       óš   — d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZ  G d„ deee   eee      f   «      Z G d„ d	e
e«      Zy
)é    )ÚAnyÚDictÚListÚOptional)Ú
Embeddings)Úpre_init)Ú	BaseModelÚ
ConfigDict)ÚContentHandlerBasec                   ó   — e Zd ZdZy)ÚEmbeddingsContentHandlerzContent handler for LLM class.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    ú{/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/sagemaker_endpoint.pyr   r   
   s   „ Ú(r   r   c            	       ó$  — e Zd ZU dZ	 dZeed<   dZeed<   	 dZ	eed<   	 dZ
ee   ed<   	 eed<   	 	 dZee   ed	<   	 dZee   ed
<   	  eddd¬«      Zededefd„«       Zdee   deee      fd„Z	 ddee   dedeee      fd„Zdedee   fd„Zy)ÚSagemakerEndpointEmbeddingsa®  Custom Sagemaker Inference Endpoints.

    To use, you must supply the endpoint name from your deployed
    Sagemaker model & the region where it is deployed.

    To authenticate, the AWS client uses the following methods to
    automatically load credentials:
    https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

    If a specific credential profile should be used, you must pass
    the name of the profile from the ~/.aws/credentials file that is to be used.

    Make sure the credentials / roles used have the required policies to
    access the Sagemaker endpoint.
    See: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html
    NÚclientÚ Úendpoint_nameÚregion_nameÚcredentials_profile_nameÚcontent_handlerÚmodel_kwargsÚendpoint_kwargsTÚforbidr   )Úarbitrary_types_allowedÚextraÚprotected_namespacesÚvaluesÚreturnc                 ó2  — |j                  d«      �|S 	 	 ddl}	 |d   �|j                  |d   ¬«      }n|j                  «       }|j                  d|d   ¬«      |d<   |S # t        $ r}t        d	|› �«      |‚d}~ww xY w# t        $ r t        d
«      ‚w xY w)z.Dont do anything if client provided externallyr   Nr   r   )Úprofile_namezsagemaker-runtimer   )r   zƒCould not load credentials to authenticate with AWS client. Please check that credentials in the specified profile name are valid. zRCould not import boto3 python package. Please install it with `pip install boto3`.)ÚgetÚboto3ÚSessionr   Ú	ExceptionÚ
ValueErrorÚImportError)Úclsr#   r(   ÚsessionÚes        r   Úvalidate_environmentz0SagemakerEndpointEmbeddings.validate_environmentu   sÛ   € ð �:‰:�hÓÐ+ØˆMàXð	ÛðØÐ4Ñ5ÐAØ#Ÿm™mØ%+Ð,FÑ%Gð ,ó ‘Gð
 $Ÿm™m›o�Gà#*§>¡>Ø'°V¸MÑ5Jð $2ó $��xÑ ð  ˆøô ò Ü ð/à/0¨cð3óð ð	ûðûô ò 	Üð>óð ð	ús)   –B ›AA! Á!	A>Á*A9Á9A>Á>B ÂBÚtextsc                 óÐ  — t        t        d„ |«      «      }| j                  xs i }| j                  xs i }| j                  j                  ||«      }| j                  j                  }| j                  j                  }	  | j                  j                  d| j                  |||dœ|¤Ž}| j                  j                  |d   «      S # t        $ r}t        d|› �«      ‚d}~ww xY w)z3Call out to SageMaker Inference embedding endpoint.c                 ó&   — | j                  dd«      S )NÚ
Ú )Úreplace)Úxs    r   Ú<lambda>z=SagemakerEndpointEmbeddings._embedding_func.<locals>.<lambda>�   s   €  1§9¡9¨T°3Ô#7r   )ÚEndpointNameÚBodyÚContentTypeÚAcceptz$Error raised by inference endpoint: Nr:   r   )ÚlistÚmapr   r   r   Útransform_inputÚcontent_typeÚacceptsr   Úinvoke_endpointr   r*   r+   Útransform_output)	Úselfr1   Ú_model_kwargsÚ_endpoint_kwargsÚbodyr@   rA   Úresponser/   s	            r   Ú_embedding_funcz+SagemakerEndpointEmbeddings._embedding_funcš   só   € ô ”SÑ7¸Ó?Ó@ˆØ×)Ñ)Ò/¨RˆØ×/Ñ/Ò5°2Ðà×#Ñ#×3Ñ3°E¸=ÓIˆØ×+Ñ+×8Ñ8ˆØ×&Ñ&×.Ñ.ˆð		IØ2�t—{‘{×2Ñ2ð Ø!×/Ñ/ØØ(Øñ	ð
 #ñˆHð ×#Ñ#×4Ñ4°X¸fÑ5EÓFÐFøô ò 	IÜÐCÀAÀ3ÐGÓHÐHûð	Iús   Â +C	 Ã		C%ÃC Ã C%Ú
chunk_sizec                 óÆ   — g }|t        |«      kD  rt        |«      n|}t        dt        |«      |«      D ]*  }| j                  ||||z    «      }|j                  |«       Œ, |S )a‹  Compute doc embeddings using a SageMaker Inference Endpoint.

        Args:
            texts: The list of texts to embed.
            chunk_size: The chunk size defines how many input texts will
                be grouped together as request. If None, will use the
                chunk size specified by the class.


        Returns:
            List of embeddings, one for each text.
        r   )ÚlenÚrangerI   Úextend)rD   r1   rJ   ÚresultsÚ_chunk_sizeÚirH   s          r   Úembed_documentsz+SagemakerEndpointEmbeddings.embed_documents³   sd   € ð ˆØ$.´°U³Ò$;”c˜%”jÀˆÜ�qœ#˜e›* kÖ2ˆAØ×+Ñ+¨E°!°a¸+±oÐ,FÓGˆHØ�N‰N˜8Õ$ð 3ð ˆr   Útextc                 ó,   — | j                  |g«      d   S )z²Compute query embeddings using a SageMaker inference endpoint.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )rI   )rD   rS   s     r   Úembed_queryz'SagemakerEndpointEmbeddings.embed_queryÉ   s   € ð ×#Ñ# T FÓ+¨AÑ.Ð.r   )é@   )r   r   r   r   r   r   Ú__annotations__r   Ústrr   r   r   r   r   r   r   r
   Úmodel_configr   r0   r   ÚfloatrI   ÚintrR   rU   r   r   r   r   r      s!  … ñð"ð< €FˆCÓà€M�3Óð,ð €K�ÓØPà.2Ð˜h s™mÓ2ðð .Ó-ðð
ð& $(€L�(˜4‘.Ó'Ø1à&*€O�X˜d‘^Ó*ðñ
 Ø $¨HÈ2ô€Lð ð"¨$ð "°4ò "ó ð"ðHG T¨#¡Yð G°4¸¸U¹Ñ3Dó Gð4 35ñØ˜#‘YðØ,/ðà	ˆd�5‰kÑ	óð,	/ ð 	/¨¨U©ô 	/r   r   N)Útypingr   r   r   r   Úlangchain_core.embeddingsr   Úlangchain_core.utilsr   Úpydanticr	   r
   Ú+langchain_community.llms.sagemaker_endpointr   rX   rZ   r   r   r   r   r   Ú<module>ra      sK   ðß ,Ó ,å 0Ý )ß *å Jô)Ð1°$°s±)¸TÀ$ÀuÁ+Ñ=NÐ2NÑOô )ôD/ )¨Zõ D/r   