
    dhP                         S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
Jr  S SKJr  S SKJrJr  \(       a  S SKrSr " S S	\5      r " S
 S\\5      rg)    )Enum)TYPE_CHECKINGAnyDictIteratorListMappingOptional)
Embeddings)pre_init)	BaseModel
ConfigDictNzocid1.generativeaiendpointc                   (    \ rS rSrSrSrSrSrSrSr	g)	OCIAuthType   z'OCI authentication types as enumerator.             N)
__name__
__module____qualname____firstlineno____doc__API_KEYSECURITY_TOKENINSTANCE_PRINCIPALRESOURCE_PRINCIPAL__static_attributes__r       h/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/oci_generative_ai.pyr   r      s    1GNr!   r   c                   ~   \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\
\   \S'    Sr\
\   \S	'    S
r\
\   \S'    Sr\
\   \S'    Sr\
\   \S'    Sr\
\   \S'    Sr\
\   \S'    Sr\
\   \S'    Sr\\S'    \" SSS9r\S\S\4S j5       r\S\\\4   4S j5       rS\\   S\\\      4S jrS\S\\   4S jr Sr!g)OCIGenAIEmbeddings   ah  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                   ^ US   b  U$  SSK m0 SUS   TR                  R                  SS.nUS   [        S5      R                  :X  a6  TR
                  R                  US	   US
   S9US'   UR                  SS5        OUS   [        S5      R                  :X  aM  S[        [        [        4   SS4U4S jjnTR
                  R                  US	   US
   S9US'   U" US   S9US'   OUS   [        S5      R                  :X  a(  TR                  R                  R                  5       US'   OOUS   [        S5      R                  :X  a(  TR                  R                  R                  5       US'   O[        S5      eTR                   R"                  " S0 UD6US'   U$ ! [$         a  n[%        S5      UeSnAf[&         a  n[        SU5      UeSnAff = f)zBValidate that OCI config and python package exists in environment.r&   Nr   r.   )
      )configsignerr.   retry_strategytimeoutr(   r   r+   r*   )file_locationprofile_namer<   r=   r   
oci_configr8   z$oci.auth.signers.SecurityTokenSignerc                 >  > TR                   R                  U R                  S5      S 5      n[        [	        U R                  S5      5      SS9 nUR                  5       nS S S 5        TR                  R                  R                  WU5      $ ! , (       d  f       N4= f)Nkey_filesecurity_token_filezutf-8)encoding)	r=   load_private_key_from_filegetopenstrreadauthsignersSecurityTokenSigner)rB   pkf	st_stringocis       r"   make_security_token_signerKOCIGenAIEmbeddings.validate_environment.<locals>.make_security_token_signer   s     >>"z2DB JNN+@ABW$%FFH	 88++??	2NN	 s   B
B)rB   r   r   z'Please provide valid value to auth_typezYCould not import oci python package. Please make sure you have the oci package installed.zCould 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   )rR   retryDEFAULT_RETRY_STRATEGYr   namer<   	from_filepopdictrJ   r   rL   rM   %InstancePrincipalsSecurityTokenSignerget_resource_principals_signer
ValueErrorgenerative_ai_inferenceGenerativeAiInferenceClientImportError	Exception)clsr7   client_kwargsrS   exerR   s         @r"   validate_environment'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(;(;;HH$$JJL h' $A(;(;;HH$$CCE h' !!JKK"::VV   F8$   	G   	M  	s$   FF 
G'F33G GGc                 8    U R                   =(       d    0 n0 SU0E$ )zGet the identifying parameters.r-   )r-   )self_model_kwargss     r"   _identifying_params&OCIGenAIEmbeddings._identifying_params   s+     ))/R
}-
 	
r!   textsc                 "  ^ ^ SSK Jn  T R                  (       d  [        S5      eT R                  R	                  [
        5      (       a  UR                  T R                  S9nOUR                  T R                  S9n/ nS[        [        [              4U U4S jjnU" 5        Hi  nUR                  UT R                  T R                  US9nT R                  R                  U5      nUR!                  UR"                  R$                  5        Mk     U$ )	zCall 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,   r8   c               3      >#    [        S[        T5      TR                  5       H  n TX TR                  -    v   M     g 7f)Nr   )rangelenr3   )iri   rm   s    r"   split_texts7OCIGenAIEmbeddings.embed_documents.<locals>.split_texts   s5     1c%j$//:ADOO 344 ;s   <?)serving_moder/   r1   inputs)oci.generative_ai_inferencero   r,   r]   
startswithCUSTOM_ENDPOINT_PREFIXDedicatedServingModeOnDemandServingModer   r   rJ   EmbedTextDetailsr/   r1   r&   
embed_textextenddata
embeddings)	ri   rm   ro   rw   r   ru   chunkinvocation_objresponses	   ``       r"   embed_documents"OCIGenAIEmbeddings.embed_documents   s     	7}}FGG==##$:;;!664==6QL!55t}}5ML
	5Xd3i0 	5 	5 !]E#44)#22	 5 N {{--n=Hhmm667 # r!   textc                 ,    U R                  U/5      S   $ )zvCall out to OCIGenAI's embedding endpoint.

Args:
    text: The text to embed.

Returns:
    Embeddings for the text.
r   )r   )ri   r   s     r"   embed_queryOCIGenAIEmbeddings.embed_query   s     ##TF+A..r!   )"r   r   r   r   r   r&   r   __annotations__r'   r(   r
   rJ   r*   r+   r,   r-   r   r.   r/   r1   r3   intr   model_configr   rf   propertyr	   rk   r   floatr   r   r    r   r!   r"   r$   r$      sQ   > FCNC(Ix}( #,L(3-+ )87 #Hhsm"H#'L(4.'0&*hsm*$(NHSM(#Hhsm#XJ H2FLJ$ J4 J JX 
WS#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   rR   r{   r   r$   r   r!   r"   <module>r      sB     N N N 0 ) *5 $ Q/J Q/r!   