
    3fi#                        d Z ddlmZ ddlmZmZ ddlmZ ddlZddl	m
Z
mZ ddlmZmZmZ ddlmZ dd	lmZ  G d
 de      Zy)z Azure OpenAI embeddings wrapper.    )annotations)	AwaitableCallable)castN)from_envsecret_from_env)Field	SecretStrmodel_validator)Self)OpenAIEmbeddingsc                     e Zd ZU dZ e edd            Zded<   	  edd	      Zded
<   	  ed e	ddgd            Z
ded<   	  e edd      d      Zded<   	  e e	dd            Zded<   	 dZded<   	 dZded<   	  e edd            Zded<   dZd ed!<   d"Zd#ed$<   	  ed%&      d)d'       Zed*d(       Zy)+AzureOpenAIEmbeddingsu  AzureOpenAI embedding model integration.

    Setup:
        To access AzureOpenAI embedding models you'll need to create an Azure account,
        get an API key, and install the `langchain-openai` integration package.

        You'll need to have an Azure OpenAI instance deployed.
        You can deploy a version on Azure Portal following this
        [guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal).

        Once you have your instance running, make sure you have the name of your
        instance and key. You can find the key in the Azure Portal,
        under the “Keys and Endpoint” section of your instance.

        ```bash
        pip install -U langchain_openai

        # Set up your environment variables (or pass them directly to the model)
        export AZURE_OPENAI_API_KEY="your-api-key"
        export AZURE_OPENAI_ENDPOINT="https://<your-endpoint>.openai.azure.com/"
        export AZURE_OPENAI_API_VERSION="2024-02-01"
        ```

    Key init args — completion params:
        model:
            Name of `AzureOpenAI` model to use.
        dimensions:
            Number of dimensions for the embeddings. Can be specified only if the
            underlying model supports it.

    See full list of supported init args and their descriptions in the params section.

    Instantiate:
        ```python
        from langchain_openai import AzureOpenAIEmbeddings

        embeddings = AzureOpenAIEmbeddings(
            model="text-embedding-3-large"
            # dimensions: int | None = None, # Can specify dimensions with new text-embedding-3 models
            # azure_endpoint="https://<your-endpoint>.openai.azure.com/", If not provided, will read env variable AZURE_OPENAI_ENDPOINT
            # api_key=... # Can provide an API key directly. If missing read env variable AZURE_OPENAI_API_KEY
            # openai_api_version=..., # If not provided, will read env variable AZURE_OPENAI_API_VERSION
        )
        ```

    Embed single text:
        ```python
        input_text = "The meaning of life is 42"
        vector = embed.embed_query(input_text)
        print(vector[:3])
        ```
        ```python
        [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
        ```

    Embed multiple texts:
        ```python
        input_texts = ["Document 1...", "Document 2..."]
        vectors = embed.embed_documents(input_texts)
        print(len(vectors))
        # The first 3 coordinates for the first vector
        print(vectors[0][:3])
        ```
        ```python
        2
        [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
        ```

    Async:
        ```python
        vector = await embed.aembed_query(input_text)
        print(vector[:3])

        # multiple:
        # await embed.aembed_documents(input_texts)
        ```
        ```python
        [-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]
        ```
    AZURE_OPENAI_ENDPOINTN)default)default_factoryz
str | Noneazure_endpointazure_deployment)r   alias
deploymentapi_keyAZURE_OPENAI_API_KEYOPENAI_API_KEY)r   r   zSecretStr | Noneopenai_api_keyOPENAI_API_VERSIONz
2023-05-15api_version)r   r   openai_api_versionAZURE_OPENAI_AD_TOKENazure_ad_tokenzCallable[[], str] | Noneazure_ad_token_providerz#Callable[[], Awaitable[str]] | Noneazure_ad_async_token_providerOPENAI_API_TYPEazureopenai_api_typeTboolvalidate_base_urli   int
chunk_sizeafter)modec                   | j                   }|rd| j                  rX| j                  s3d|vr/t        t        | j                         dz   | _         d}t        |      | j                  rd}t        |      | j                  | j                  | j                  | j                  r| j                  j                         nd| j                  r| j                  j                         nd| j                  | j                  | j                   | j                  | j                  i | j                  xs i ddi| j                   d}| j"                  s4d| j$                  i}t'        j(                  d
i ||j*                  | _        | j,                  sOd| j.                  i}| j0                  r| j0                  |d	<   t'        j2                  d
i ||j*                  | _        | S )z?Validate that api key and python package exists in environment.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`). 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`.Nz
User-Agentz%langchain-partner-python-azure-openai)r   r   r   r   r   r    organizationbase_urltimeoutmax_retriesdefault_headersdefault_queryhttp_clientr     )openai_api_baser&   r   r   str
ValueErrorr   r   r   get_secret_valuer   r    openai_organizationrequest_timeoutr/   r0   r1   clientr2   openaiAzureOpenAI
embeddingsasync_clienthttp_async_clientr!   AsyncAzureOpenAI)selfr4   msgclient_paramssync_specificasync_specifics         _/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_openai/embeddings/azure.pyvalidate_environmentz*AzureOpenAIEmbeddings.validate_environment   s   
 ..t55&&9O+K'+C1E1E'F'R$. 
 !o%,  !o%22"11 $:>:M:M##446SW ;?:M:M##446SW'+'C'C 44,,++++ ''-2 E  "//'
* {{#0$2B2B"CM ,,  j K   $143I3I#JN1166 78 !' 7 7 !! ! j      c                     y)Nzazure-openai-chatr3   )rA   s    rF   	_llm_typezAzureOpenAIEmbeddings._llm_type   s    "rH   )returnr   )rK   r5   )__name__
__module____qualname____doc__r	   r   r   __annotations__r   r   r   r   r   r    r!   r$   r&   r(   r   rG   propertyrJ   r3   rH   rF   r   r      sJ   Ob "' !8$G"NJ  #47IJJ
J (-'#%56
(N$  V%* !5|L&
 
 (-'(?N(N$  9=5<
 JN!#FM #( !2GD#OZ  #t"J8'"? #?B # #rH   r   )rO   
__future__r   collections.abcr   r   typingr   r;   langchain_core.utilsr   r   pydanticr	   r
   r   typing_extensionsr    langchain_openai.embeddings.baser   r   r3   rH   rF   <module>rY      s2    & " /   : 6 6 " =V#, V#rH   