Ë
    ´Œj,$  ã                  ó’   — d Z ddlm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 dd	lmZ  G d
„ de«      Zy)z Azure OpenAI embeddings wrapper.é    )Úannotations)Ú	Awaitable)ÚCallableÚOptionalÚUnionÚ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.

        .. 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]

    ÚAZURE_OPENAI_ENDPOINTN)Údefault)Údefault_factoryzOptional[str]Úazure_endpointÚazure_deployment)r   ÚaliasÚ
deploymentÚapi_keyÚAZURE_OPENAI_API_KEYÚOPENAI_API_KEY)r   r   zOptional[SecretStr]Úopenai_api_keyÚOPENAI_API_VERSIONz
2023-05-15Úapi_version)r   r   Úopenai_api_versionÚAZURE_OPENAI_AD_TOKENÚazure_ad_tokenzUnion[Callable[[], str], None]Úazure_ad_token_providerz)Union[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                   }|rT| j                  rHd|vr-t        t        | j                   «      dz   | _         t	        d«      ‚| j
                  rt	        d«      ‚| 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/openaiz…As of openai>=1.0.0, Azure endpoints should be specified via the `azure_endpoint` param not `openai_api_base` (or alias `base_url`). zØAs 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   ÚstrÚ
ValueErrorr   r   r   r   Úget_secret_valuer!   r"   Úopenai_organizationÚrequest_timeoutr1   r2   r3   Úclientr4   ÚopenaiÚAzureOpenAIÚ
embeddingsÚasync_clientÚhttp_async_clientr#   ÚAsyncAzureOpenAI)Úselfr6   Úclient_paramsÚsync_specificÚasync_specifics        úk/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_openai/embeddings/azure.pyÚvalidate_environmentz*AzureOpenAIEmbeddings.validate_environment©   sÕ  € ð
 ×.Ñ.ˆÙ˜t×5Ò5Ø Ñ/Ü'+¬C°×1EÑ1EÓ'FÈÑ'R�Ô$Ü ð.óð ð
 �ŠÜ ð,óð ð  ×2Ñ2Ø"×1Ñ1Ø $§¡à:>×:MÒ:M�×#Ñ#×4Ñ4Ô6ÐSWð ;?×:MÒ:M�×#Ñ#×4Ñ4Ô6ÐSWà'+×'CÑ'CØ ×4Ñ4Ø×,Ñ,Ø×+Ñ+Ø×+Ñ+ð Ø×'Ñ'Ò-¨2ð àÐEñ ð "×/Ñ/ñ'
ˆð* �{Š{Ø#0°$×2BÑ2BÐ"CˆMÜ ×,Ñ,ñ Øðàñ÷ ‰jð ŒKð × Ò Ø$1°4×3IÑ3IÐ#JˆNà×1Ò1à×6Ñ6ð Ð7Ñ8ô !'× 7Ñ 7ñ !Øð!à ñ!÷ ‰jð Ôð ˆó    c                 ó   — y)Nzazure-openai-chatr5   )rC   s    rG   Ú	_llm_typezAzureOpenAIEmbeddings._llm_typeè   s   € à"rI   )Úreturnr   )rL   r7   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   Ú__annotations__r   r
   r   r   r!   r"   r#   r&   r(   r*   r   rH   ÚpropertyrK   r5   rI   rG   r   r      sK  … ñVñp %*Ù Ð!8À$ÔGô%€N�Mó ðñ !&¨dÐ:LÔ M€J�ÓMðñ +0ØÙ'Ø#Ð%5Ð6Àô
ô+€NÐ'ó ð XÙ(-Ù Ð!5¸|ÔLØô)Ð˜ó ðñ
 +0Ù'Ð(?ÈÔNô+€NÐ'ó ðð ?CÐÐ;ÓBðð
 PTÐ!Ð#LÓSðñ &+Ù Ð!2¸GÔDô&€O�]ó ð #Ð�tÓ"Ø€J�ÓØ8á˜'Ô"ò<ó #ð<ð| ò#ó ñ#rI   r   )rP   Ú
__future__r   Úcollections.abcr   Útypingr   r   r   r   r=   Úlangchain_core.utilsr	   r
   Úpydanticr   r   r   Útyping_extensionsr   Ú langchain_openai.embeddings.baser   r   r5   rI   rG   Ú<module>rZ      s5   ðÙ &å "å %ß 2Ó 2ã ß :ß 6Ñ 6Ý "å =ôZ#Ð,õ Z#rI   