§
    šŠtj)  ã                   ó¨   — 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dS )é    )Ú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dS )ÚOCIAuthTypez'OCI authentication types as enumerator.é   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚAPI_KEYÚSECURITY_TOKENÚINSTANCE_PRINCIPALÚRESOURCE_PRINCIPAL© ó    ún/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/embeddings/oci_generative_ai.pyr   r      s,   € € € € € Ø1Ð1à€GØ€NØÐØÐÐÐr   r   c                   óÖ  — 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dS )Ú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_classic.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    rC‰j                             |d	         |d
         ¬¦  «        |d<   |                     dd¦  «         �n|d         t          d¦  «        j        k    rbdt          t          t          f         ddfˆfd„}‰j                             |d	         |d
         ¬¦  «        |d<    ||d         ¬¦  «        |d<   n�|d         t          d¦  «        j        k    r"‰j        j                             ¦   «         |d<   nO|d         t          d¦  «        j        k    r"‰j        j                             ¦   «         |d<   nt          d¦  «        ‚ ‰j        j        di |¤Ž|d<   n@# t$          $ r}t%          d¦  «        |‚d}~wt&          $ r}t          d|¦  «        |‚d}~ww xY w|S )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                 óZ  •— ‰j                              |                      d¦  «        d ¦  «        }t          t	          |                      d¦  «        ¦  «        d¬¦  «        5 }|                     ¦   «         }d d d ¦  «         n# 1 swxY w Y   ‰j        j                             ||¦  «        S )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Ô2°Dñô �Bõ Ý˜JŸNšNÐ+@ÑAÔAÑBÔBÈWðñ ô ð -àØ$%§F¢F¡H¤H˜	ð-ð -ð -ñ -ô -ð -ð -ð -ð -ð -ð -øøøð -ð -ð -ð -ð œ8Ô+×?Ò?À	È2ÑNÔNÐNs   Á!BÂ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	ØˆJˆJˆJð ØØ$*Ð+=Ô$>Ø"%¤)Ô"BØ$ðð ˆMð �kÔ"¥k°!¡n¤nÔ&9Ò9Ð9Ø*-¬*×*>Ò*>Ø"(Ð)=Ô">Ø!'¨Ô!7ð +?ñ +ô +�˜hÑ'ð ×!Ò! (¨DÑ1Ô1Ð1Ñ1Ø˜Ô$­°A©¬Ô(;Ò;Ð;ð
OÝ $¥S­# X¤ð
Oà;ð
Oð 
Oð 
Oð 
Oð 
Oð 
Oð +.¬*×*>Ò*>Ø"(Ð)=Ô">Ø!'¨Ô!7ð +?ñ +ô +�˜hÑ'ð +EÐ*DØ,¨XÔ6ð+ñ +ô +�˜hÑ'Ð'ð ˜Ô$­°A©¬Ô(;Ò;Ð;à”HÔ$×JÒJÑLÔLð ˜hÑ'Ð'ð ˜Ô$­°A©¬Ô(;Ò;Ð;à”HÔ$×CÒCÑEÔEð ˜hÑ'Ð'õ !Ð!JÑKÔKÐKàV˜sÔ:ÔVð  ð  Øð ð  ˆF�8ÑÐøõ ð 	ð 	ð 	ÝðGñô ð ðøøøøõ ð 	ð 	ð 	ÝðMð ñô ð ðøøøøð	øøøð ˆs$   �F!F/ Æ/
G,Æ9G	Ç	G,ÇG'Ç'G,c                 ó    — | j         p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                             t
          ¦  «        r|                     ‰ j        ¬¦  «        }n|                     ‰ j        ¬¦  «        }g }dt          t          t                            fˆ ˆfd„} |¦   «         D ]^}|                     |‰ j        ‰ j        |¬¦  «        }‰ j                             |¦  «        }|                     |j        j        ¦  «         Œ_|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   …         V — Œd S )Nr   )ÚrangeÚlenr/   )Úirc   rf   s    €€r   Úsplit_textsz7OCIGenAIEmbeddings.embed_documents.<locals>.split_textsÏ   sT   øè è € Ý˜1�c %™jœj¨$¬/Ñ:Ô:ð 5ð 5�Ø˜A  D¤OÑ 3Ð3Ô4Ð4Ð4Ð4Ð4ð5ð 5r   )Ú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º   s1  øø€ ð 	7Ð6Ð6Ð6Ð6Ð6àŒ}ð 	HÝÐFÑGÔGÐGàŒ=×#Ò#Õ$:Ñ;Ô;ð 	NØ!×6Ò6À4Ä=Ð6ÑQÔQˆLˆLà!×5Ò5¸t¼}Ð5ÑMÔMˆLàˆ
ð	5�X¥d­3¤iÔ0ð 	5ð 	5ð 	5ð 	5ð 	5ð 	5ð 	5ð !�[‘]”]ð 	8ð 	8ˆEØ#×4Ò4Ø)Ø#Ô2ØœØð	 5ñ ô ˆNð ”{×-Ò-¨nÑ=Ô=ˆHØ×Ò˜hœmÔ6Ñ7Ô7Ð7Ð7àÐr   Útextc                 ó:   — |                       |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!      sì  € € € € € € ðð ð> €FˆCÐÐÑà€N�CÐÐÑà(€Iˆx˜Œ}Ð(Ð(Ñ(ðð #,€L�(˜3”-Ð+Ð+Ñ+ðð )8Ð˜ œÐ7Ð7Ñ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ÑFÔF€LàðJ¨$ð J°4ð Jð Jð Jñ „XðJðX ð
 W¨S°#¨XÔ%6ð 
ð 
ð 
ñ „Xð
ð# 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Œ      s
  ðØ Ð Ð Ð Ð Ð Ø NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ NÐ Nà 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø )Ð )Ð )Ð )Ð )Ð )Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *àð Ø€J€J€Jà5Ð ðð ð ð ð �$ñ ô ð ðQ/ð Q/ð Q/ð Q/ð Q/˜ Jñ Q/ô Q/ð Q/ð Q/ð Q/r   