a
    `g#                     @  s   d Z ddlmZ ddlmZmZmZ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mZ ddlmZ G d	d
 d
eZdS )z Azure OpenAI embeddings wrapper.    )annotations)	AwaitableCallableOptionalUnionN)from_envsecret_from_env)Field	SecretStrmodel_validator)Selfcast)OpenAIEmbeddingsc                   @  s
  e Zd ZU dZeeddddZded< eddd	Zded
< ede	ddgdddZ
ded< eedddddZded< ee	ddddZded< dZded< dZded< eeddddZded< dZd ed!< d"Zd#ed$< ed%d&d'd(d)d*Zed+d(d,d-ZdS ).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.

        .. code-block:: 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: str
            Name of AzureOpenAI model to use.
        dimensions: Optional[int]
            Number of dimensions for the embeddings. Can be specified only
            if the underlying model supports it.

    Key init args — client params:
      api_key: Optional[SecretStr]

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

    Instantiate:
        .. code-block:: python

            from langchain_openai import AzureOpenAIEmbeddings

            embeddings = AzureOpenAIEmbeddings(
                model="text-embedding-3-large"
                # dimensions: Optional[int] = 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:
        .. code-block:: python

            input_text = "The meaning of life is 42"
            vector = embed.embed_query(input_text)
            print(vector[:3])

        .. code-block:: python

            [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]

    Embed multiple texts:
        .. code-block:: 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])

        .. code-block:: python

            2
            [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]

    Async:
        .. code-block:: python

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

            # multiple:
            # await embed.aembed_documents(input_texts)

        .. code-block:: python

            [-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]
    ZAZURE_OPENAI_ENDPOINTN)default)default_factoryzOptional[str]azure_endpointazure_deployment)r   alias
deploymentapi_keyZAZURE_OPENAI_API_KEYZOPENAI_API_KEY)r   r   zOptional[SecretStr]openai_api_keyZOPENAI_API_VERSIONz
2023-05-15api_version)r   r   openai_api_versionZAZURE_OPENAI_AD_TOKENazure_ad_tokenzUnion[Callable[[], str], None]azure_ad_token_providerz)Union[Callable[[], Awaitable[str]], None]azure_ad_async_token_providerZOPENAI_API_TYPEZazureopenai_api_typeTboolvalidate_base_urli   int
chunk_sizeafter)moder   )returnc                 C  s  | j }|r@| jr@d|vr2tt| j d | _ td| jr@td| j| j| j| jr\| j	 nd| j
rn| j
	 nd| j| j| j | j| ji | jpi ddi| jd}| jsd| ji}tjf i ||j| _| jsd| ji}| jr| j|d	< tjf 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   Zorganizationbase_urltimeoutmax_retriesdefault_headersdefault_queryhttp_clientr   )openai_api_baser   r   str
ValueErrorr   r   r   r   Zget_secret_valuer   r   Zopenai_organizationrequest_timeoutr'   r(   r)   clientr*   openaiZAzureOpenAIZ
embeddingsZasync_clientZhttp_async_clientr   ZAsyncAzureOpenAI)selfr+   Zclient_paramsZsync_specificZasync_specific r2   o/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_openai/embeddings/azure.pyvalidate_environment   s\    




z*AzureOpenAIEmbeddings.validate_environmentr,   c                 C  s   dS )Nzazure-openai-chatr2   )r1   r2   r2   r3   	_llm_type   s    zAzureOpenAIEmbeddings._llm_type)__name__
__module____qualname____doc__r	   r   r   __annotations__r   r   r   r   r   r   r   r   r   r!   r   r4   propertyr5   r2   r2   r2   r3   r      s:   
W
		



>r   )r9   
__future__r   typingr   r   r   r   r0   Zlangchain_core.utilsr   r   Zpydanticr	   r
   r   Ztyping_extensionsr   r   Z langchain_openai.embeddings.baser   r   r2   r2   r2   r3   <module>   s   