
    dh~                        S r SSKJr  SSKrSSKrSSK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  SSKJr  SS	KJr  SS
KJr  \" SSSS9 " S S\5      5       rg)z Azure OpenAI embeddings wrapper.    )annotationsN)Any	AwaitableCallableDictOptionalUnion)
deprecated)get_from_dict_or_env)Fieldmodel_validator)Self)OpenAIEmbeddings)is_openai_v1z0.0.9z1.0z&langchain_openai.AzureOpenAIEmbeddings)sinceremovalalternative_importc                     \ rS rSr% SrSrS\S'    \" SSS9rS\S	'    \" SS
S9r	S\S'    Sr
S\S'    SrS\S'    SrS\S'    \" SSS9rS\S'    SrS\S'   \" SS9\SS j5       5       r\" SS9SS j5       r\SS j5       rSrg) AzureOpenAIEmbeddings   z`Azure OpenAI` Embeddings API.NzUnion[str, None]azure_endpointazure_deployment)defaultaliaszOptional[str]
deploymentapi_keyopenai_api_keyazure_ad_tokenzUnion[Callable[[], str], None]azure_ad_token_providerz)Union[Callable[[], Awaitable[str]], None]azure_ad_async_token_providerapi_versionopenai_api_versionTboolvalidate_base_urlbefore)modec                   UR                  S5      =(       d3    [        R                  " S5      =(       d    [        R                  " S5      US'   UR                  S5      =(       d    [        R                  " S5      US'   UR                  S5      =(       d    [        R                  " SSS	9US'   [        US
SSS	9US
'   UR                  S5      =(       d3    [        R                  " S5      =(       d    [        R                  " S5      US'   [        USSSS	9US'   UR                  S5      =(       d    [        R                  " S5      US'   UR                  S5      =(       d    [        R                  " S5      US'   [	        US   S5      US'    SSKn[        5       (       a  US   nU(       a  US   (       a  SU;  a-  US==   S-  ss'   [        R                  " SU SUS    S 35        US!   (       aZ  [        R                  " S"5        US!   US   ;  a3  [        R                  " S#U SUS    S 35        US==   S$US!   -   -  ss'   SUS!'   U$ ! [         a    [        S5      ef = f)%z?Validate that api key and python package exists in environment.r   AZURE_OPENAI_API_KEYOPENAI_API_KEYopenai_api_baseOPENAI_API_BASEr"   OPENAI_API_VERSIONz
2023-05-15)r   openai_api_typeOPENAI_API_TYPEazureopenai_organizationOPENAI_ORG_IDOPENAI_ORGANIZATIONopenai_proxyOPENAI_PROXY r   AZURE_OPENAI_ENDPOINTr   AZURE_OPENAI_AD_TOKEN
chunk_sizei   r   NzTCould not import openai python package. Please install it with `pip install openai`.r$   z/openaizAs of openai>=1.0.0, Azure endpoints should be specified via the `azure_endpoint` param not `openai_api_base` (or alias `base_url`). Updating `openai_api_base` from z to .r   zAs of openai>=1.0.0, if `deployment` (or alias `azure_deployment`) is specified then `openai_api_base` (or alias `base_url`) should not be. Instead use `deployment` (or alias `azure_deployment`) and `azure_endpoint`.zAs of openai>=1.0.0, if `openai_api_base` (or alias `base_url`) is specified it is expected to be of the form https://example-resource.azure.openai.com/openai/deployments/example-deployment. Updating z/deployments/)
getosgetenvr   minopenaiImportErrorr   warningswarn)clsvaluesr>   r*   s       c/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/embeddings/azure_openai.pyvalidate_environment*AzureOpenAIEmbeddings.validate_environment@   s    JJ'( +yy/0+yy)* 	 
 %+JJ/@$A %
RYYF
 ! (.zz2F'G (
299 ,L
#$ %9%'8'%
 ! JJ,- 0yy)0yy./ 	$%
 "6	"
~ $*::.>#? $
299#D
  $*::.>#? $
299#D
   #6,#7>|	 >> %%67O6*=#>O3,-:-MMR ++47H0I/J!M ,'MM0 l+6:K3LL ( )8'8%&789< 01+f\.BB1 ,0F<(O  	? 	s   I I)afterc                Z   SSK n[        5       (       Ga  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  0 U R                  =(       d    0 ESS0EU R                  U R                  S.nUR                  " S0 UD6R                   U l        U R$                  (       a  U R$                  US'   UR&                  " S0 UD6R                   U l        U $ UR*                  U l        U $ )z"Validate that the base url is set.r   Nz
User-Agentz"langchain-comm-python-azure-openai)r!   r   r   r   r   r   organizationbase_urltimeoutmax_retriesdefault_headersdefault_queryhttp_clientr    )r>   r   r"   r   r   r   r   r   r0   r*   request_timeoutrL   rM   rN   rO   AzureOpenAI
embeddingsclientr    AsyncAzureOpenAIasync_client	Embedding)selfr>   client_paramss      rD   post_init_validator)AzureOpenAIEmbeddings.post_init_validator   s    	>>#66"&"5"5$(OO.."&"5"5+/+G+G $ 8 8 00//#//$++1r$ "F$ "&!3!3#//!M$ !,,=}=HHDK1166 78 !' 7 7 H- H S SD  !**DK    c                    g)Nzazure-openai-chatrP   )rX   s    rD   	_llm_typeAzureOpenAIEmbeddings._llm_type   s    "r\   )rV   rT   )rC   r   returnr   )r`   r   )r`   str)__name__
__module____qualname____firstlineno____doc__r   __annotations__r   r   r   r   r   r    r"   r$   r   classmethodrE   rZ   propertyr^   __static_attributes__rP   r\   rD   r   r      s     )'+N$+ !&d:L MJM
 (-T'KN$KU'+N$+ ?C;B
 PT!#LS ).d-(PPS"t"(#Q  $Qf '"! #!F # #r\   r   )rf   
__future__r   r;   r@   typingr   r   r   r   r   r	   langchain_core._api.deprecationr
   langchain_core.utilsr   pydanticr   r   typing_extensionsr   %langchain_community.embeddings.openair    langchain_community.utils.openair   r   rP   r\   rD   <module>rs      sV    & " 	  B B 6 5 + " B 9 
?
d#, d#
d#r\   