Ë
    µŒjP  ã                   óš   — d dl mZ d dlmZmZmZ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 erd dlZdZ G d„ d	e«      Z G d
„ dee«      Zy)é    )ÚEnum)ÚTYPE_CHECKINGÚAnyÚDictÚIteratorÚListÚMappingÚOptional)Ú
Embeddings)Úpre_init)Ú	BaseModelÚ
ConfigDictNzocid1.generativeaiendpointc                   ó    — e Zd ZdZdZdZdZdZy)ÚOCIAuthTypez'OCI authentication types as enumerator.é   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚAPI_KEYÚSECURITY_TOKENÚINSTANCE_PRINCIPALÚRESOURCE_PRINCIPAL© ó    úz/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/oci_generative_ai.pyr   r      s   „ Ù1à€GØ€NØÐØÑr   r   c                   ót  — e Zd ZU dZdZeed<   dZeed<   dZe	e
   ed<   	 dZe	e
   ed<   	 d	Ze	e
   ed
<   	 dZe	e
   ed<   	 dZe	e   ed<   	 dZe	e
   ed<   	 dZe	e
   ed<   	 dZe	e
   ed<   	 d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
dee   fd„Zy)ÚOCIGenAIEmbeddingsaÀ  OCI embedding models.

    To authenticate, the OCI client uses the methods described in
    https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_authentication_methods.htm

    The authentifcation method is passed through auth_type and should be one of:
    API_KEY (default), SECURITY_TOKEN, INSTANCE_PRINCIPLE, RESOURCE_PRINCIPLE

    Make sure you have the required policies (profile/roles) to
    access the OCI Generative AI service. If a specific config profile is used,
    you must pass the name of the profile (~/.oci/config) through auth_profile.
    If a specific config file location is used, you must pass
    the file location where profile name configs present
    through auth_file_location

    To use, you must provide the compartment id
    along with the endpoint url, and model id
    as named parameters to the constructor.

    Example:
        .. code-block:: python

            from langchain.embeddings import OCIGenAIEmbeddings

            embeddings = OCIGenAIEmbeddings(
                model_id="MY_EMBEDDING_MODEL",
                service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
                compartment_id="MY_OCID"
            )
    NÚclientÚservice_modelsr   Ú	auth_typeÚDEFAULTÚauth_profilez~/.oci/configÚauth_file_locationÚmodel_idÚmodel_kwargsÚservice_endpointÚcompartment_idÚENDÚtruncateé`   Ú
batch_sizeÚforbidr   )ÚextraÚprotected_namespacesÚvaluesÚreturnc                 óª  ‡— |d   �|S 	 ddl Ši d|d   ‰j                  j                  ddœ}|d   t        d«      j                  k(  r9‰j
                  j                  |d	   |d
   ¬«      |d<   |j                  dd«       ný|d   t        d«      j                  k(  rQdt        t        t        f   ddfˆfd„}‰j
                  j                  |d	   |d
   ¬«      |d<    ||d   ¬«      |d<   n‘|d   t        d«      j                  k(  r(‰j                  j                  j                  «       |d<   nN|d   t        d«      j                  k(  r(‰j                  j                  j                  «       |d<   nt        d«      ‚ ‰j                   j"                  di |¤Ž|d<   |S # t$        $ r}t%        d«      |‚d}~wt&        $ r}t        d|«      |‚d}~ww xY w)zBValidate that OCI config and python package exists in environment.r"   Nr   r*   )é
   éð   )ÚconfigÚsignerr*   Úretry_strategyÚtimeoutr$   r   r'   r&   )Úfile_locationÚprofile_namer8   r9   r   Ú
oci_configr4   z$oci.auth.signers.SecurityTokenSignerc                 ó:  •— ‰j                   j                  | j                  d«      d «      }t        t	        | j                  d«      «      d¬«      5 }|j                  «       }d d d «       ‰j                  j                  j                  |«      S # 1 sw Y   Œ/xY w)NÚkey_fileÚsecurity_token_filezutf-8)Úencoding)	r9   Úload_private_key_from_fileÚgetÚopenÚstrÚreadÚauthÚsignersÚSecurityTokenSigner)r>   ÚpkÚfÚ	st_stringÚocis       €r   Úmake_security_token_signerzKOCIGenAIEmbeddings.validate_environment.<locals>.make_security_token_signer€   s‚   ø€ ð Ÿ™×>Ñ>Ø"Ÿ™ zÓ2°Dó�Bô Ü˜JŸN™NÐ+@ÓAÓBÈWõàØ$%§F¡F£H˜	÷ð Ÿ8™8×+Ñ+×?Ñ?À	È2ÓNÐN÷	ð ús   ÁBÂB)r>   r   r   z'Please provide valid value to auth_typezYCould not import oci python package. Please make sure you have the oci package installed.záCould not authenticate with OCI client.
                If INSTANCE_PRINCIPAL or RESOURCE_PRINCIPAL is used,
                please check the specified
                auth_profile, auth_file_location and auth_type are valid.r   )rN   ÚretryÚDEFAULT_RETRY_STRATEGYr   Únamer8   Ú	from_fileÚpopÚdictrF   r   rH   rI   Ú%InstancePrincipalsSecurityTokenSignerÚget_resource_principals_signerÚ
ValueErrorÚgenerative_ai_inferenceÚGenerativeAiInferenceClientÚImportErrorÚ	Exception)Úclsr3   Úclient_kwargsrO   ÚexÚerN   s         @r   Úvalidate_environmentz'OCIGenAIEmbeddings.validate_environmente   s   ø€ ð
 �(ÑÐ'ØˆMðA	Ûð ØØ$*Ð+=Ñ$>Ø"%§)¡)×"BÑ"BØ$ñˆMð �kÑ"¤k°!£n×&9Ñ&9Ò9Ø*-¯*©*×*>Ñ*>Ø"(Ð)=Ñ">Ø!'¨Ñ!7ð +?ó +�˜hÑ'ð ×!Ñ! (¨DÕ1Ø˜Ñ$¬°A«×(;Ñ(;Ò;ð
OÜ $¤S¬# X¡ð
Oà;õ
Oð +.¯*©*×*>Ñ*>Ø"(Ð)=Ñ">Ø!'¨Ñ!7ð +?ó +�˜hÑ'ñ +EØ,¨XÑ6ô+�˜hÒ'ð ˜Ñ$¬°A«×(;Ñ(;Ò;à—H‘H×$Ñ$×JÑJÓLð ˜hÒ'ð ˜Ñ$¬°A«×(;Ñ(;Ò;à—H‘H×$Ñ$×CÑCÓEð ˜hÒ'ô !Ð!JÓKÐKàV˜s×:Ñ:×VÑVñ  Øñ ˆF�8Ñð$ ˆøô ò 	ÜðGóð ðûô ò 	ÜðMð óð ðûð	ús$   ŠFF Æ	GÆ(F4Æ4GÇ GÇGc                 ó.   — | j                   xs i }i d|i¥S )zGet the identifying parameters.r)   )r)   )ÚselfÚ_model_kwargss     r   Ú_identifying_paramsz&OCIGenAIEmbeddings._identifying_params²   s+   € ð ×)Ñ)Ò/¨Rˆð
Ø˜}Ð-ð
ð 	
r   Útextsc                 ó  ‡ ‡— ddl m} ‰ j                  st        d«      ‚‰ j                  j	                  t
        «      r|j                  ‰ j                  ¬«      }n|j                  ‰ j                  ¬«      }g }dt        t        t              fˆ ˆfd„} |«       D ]k  }|j                  |‰ j                  ‰ j                  |¬«      }‰ j                  j                  |«      }|j!                  |j"                  j$                  «       Œm |S )	z¶Call out to OCIGenAI's embedding endpoint.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        r   )Úmodelsz'Model ID is required to embed documents)Úendpoint_id)r(   r4   c               3   ó€   •K  — t        dt        ‰«      ‰j                  «      D ]  } ‰| | ‰j                  z    –— Œ y ­w)Nr   )ÚrangeÚlenr/   )Úirc   rf   s    €€r   Úsplit_textsz7OCIGenAIEmbeddings.embed_documents.<locals>.split_textsÏ   s8   øè ø€ Ü˜1œc %›j¨$¯/©/Ö:�Ø˜A  D§O¡OÑ 3Ð4Ó4ñ ;ùs   ƒ;>)Úserving_moder+   r-   Úinputs)Úoci.generative_ai_inferencerh   r(   rX   Ú
startswithÚCUSTOM_ENDPOINT_PREFIXÚDedicatedServingModeÚOnDemandServingModer   r   rF   ÚEmbedTextDetailsr+   r-   r"   Ú
embed_textÚextendÚdataÚ
embeddings)	rc   rf   rh   ro   rz   rn   ÚchunkÚinvocation_objÚresponses	   ``       r   Úembed_documentsz"OCIGenAIEmbeddings.embed_documentsº   så   ù€ õ 	7à�}Š}ÜÐFÓGÐGà�=‰=×#Ñ#Ô$:Ô;Ø!×6Ñ6À4Ç=Á=Ð6ÓQ‰Là!×5Ñ5¸t¿}¹}Ð5ÓMˆLàˆ
ð	5œX¤d¬3¡iÑ0ö 	5ñ !–]ˆEØ#×4Ñ4Ø)Ø#×2Ñ2ØŸ™Øð	 5ó ˆNð —{‘{×-Ñ-¨nÓ=ˆHØ×Ñ˜hŸm™m×6Ñ6Õ7ð #ð Ðr   Útextc                 ó,   — | j                  |g«      d   S )zžCall out to OCIGenAI's embedding endpoint.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   )r~   )rc   r   s     r   Úembed_queryzOCIGenAIEmbeddings.embed_queryß   s   € ð ×#Ñ# T FÓ+¨AÑ.Ð.r   ) r   r   r   r   r"   r   Ú__annotations__r#   r$   r
   rF   r&   r'   r(   r)   r   r*   r+   r-   r/   Úintr   Úmodel_configr   ra   Úpropertyr	   re   r   Úfloatr~   r�   r   r   r   r!   r!      sQ  … ñð> €FˆCÓà€N�CÓà(€Iˆx˜‰}Ó(ðð #,€L�(˜3‘-Ó+ðð )8Ð˜ ™Ó7ðð #€Hˆh�s‰mÓ"ØHà#'€L�(˜4‘.Ó'Ø0à&*Ð�h˜s‘mÓ*Øà$(€N�H˜S‘MÓ(Øà#€Hˆh�s‰mÓ#ØXà€J�Óðñ  HÀ2ÔF€LàðJ¨$ð J°4ò Jó ðJðX ð
 W¨S°#¨XÑ%6ò 
ó ð
ð# T¨#¡Yð #°4¸¸U¹Ñ3Dó #ðJ	/ ð 	/¨¨U©ô 	/r   r!   )Úenumr   Útypingr   r   r   r   r   r	   r
   Úlangchain_core.embeddingsr   Úlangchain_core.utilsr   Úpydanticr   r   rN   rs   r   r!   r   r   r   Ú<module>rŒ      sB   ðÝ ß N× NÑ Nå 0Ý )ß *áÛà5Ð ô�$ô ôQ/˜ Jõ Q/r   