HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langchain_openai/llms/__pycache__/azure.cpython-310.pyc
o

;��g� �@s�ddlmZddlZddlmZmZmZmZmZm	Z	m
Z
mZddlZddl
mZddlmZmZddlmZmZmZddlmZmZddlmZe�e�ZGd	d
�d
e�ZdS)�)�annotationsN)�Any�	Awaitable�Callable�Dict�List�Mapping�Optional�Union)�LangSmithParams)�from_env�secret_from_env)�Field�	SecretStr�model_validator)�Self�cast)�
BaseOpenAIcsxeZdZUdZeeddd�d�Zded<	eddd	�Zd
ed<	eded
dd�d�Z	ded<	ede
ddgdd�d�Zded<ee
ddd�d�Zded<	dZ
ded<	dZded<	eeddd�d�Zded<	dZded <	edAd#d$��ZedBd&d'��ZedCd(d)��Zed*d+�dDd-d.��ZedE�fd0d1��ZedF�fd3d4��Z	dGdH�fd:d;�
ZedId=d>��ZedFd?d@��Z�ZS)J�AzureOpenAIa�Azure-specific OpenAI large language models.

    To use, you should have the ``openai`` python package installed, and the
    environment variable ``OPENAI_API_KEY`` set with your API key.

    Any parameters that are valid to be passed to the openai.create call can be passed
    in, even if not explicitly saved on this class.

    Example:
        .. code-block:: python

            from langchain_openai import AzureOpenAI

            openai = AzureOpenAI(model_name="gpt-3.5-turbo-instruct")
    �AZURE_OPENAI_ENDPOINTN)�default)�default_factoryz
Optional[str]�azure_endpoint�azure_deployment)r�aliaszUnion[str, None]�deployment_name�api_version�OPENAI_API_VERSION)rr�openai_api_version�api_key�AZURE_OPENAI_API_KEY�OPENAI_API_KEYzOptional[SecretStr]�openai_api_key�AZURE_OPENAI_AD_TOKEN�azure_ad_tokenzUnion[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_url�return�	List[str]cCsgd�S)z*Get the namespace of the langchain object.)�	langchain�llms�openai���clsr1r1�F/usr/local/lib/python3.10/dist-packages/langchain_openai/llms/azure.py�get_lc_namespace]szAzureOpenAI.get_lc_namespace�Dict[str, str]cCs
ddd�S)Nr r#)r"r$r1��selfr1r1r4�
lc_secretsbs�zAzureOpenAI.lc_secretscC�dS)z9Return whether this model can be serialized by Langchain.Tr1r2r1r1r4�is_lc_serializablei�zAzureOpenAI.is_lc_serializable�after)�moderc
CsN|jdkr	td��|jr|jdkrtd��|jr!|jdkr!td��|j}|rD|jrDd|vr=tt|j��d�d|_td��|j	rDtd��|j
|j|j	|jrR|j�
�nd	|jr[|j�
�nd	|j|j|j|j|ji|jpki�d
di�|jd�}|js�d
|ji}tjdi|�|��j|_|js�d
|ji}|jr�|j|d<tjdi|�|��j|_|S)z?Validate that api key and python package exists in environment.�zn must be at least 1.z!Cannot stream results when n > 1.z'Cannot stream results when best_of > 1.z/openai�/z�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_name` (or alias `azure_deployment`) is specified then `openai_api_base` (or alias `base_url`) should not be. Instead use `deployment_name` (or alias `azure_deployment`) and `azure_endpoint`.Nz
User-Agentz%langchain-partner-python-azure-openai)rrrrr$r%�organization�base_url�timeout�max_retries�default_headers�
default_query�http_clientr%r1)�n�
ValueError�	streaming�best_of�openai_api_baser+r�str�rstriprrrr"�get_secret_valuer$r%�openai_organization�request_timeoutrDrErF�clientrGr0r�completions�async_client�http_async_clientr&�AsyncAzureOpenAI)r8rL�
client_params�
sync_specific�async_specificr1r1r4�validate_environmentnsz

���	�����
���
����z AzureOpenAI.validate_environment�Mapping[str, Any]csid|ji�t�j�S)Nr)r�super�_identifying_paramsr7��	__class__r1r4r]�s
��zAzureOpenAI._identifying_params�Dict[str, Any]csd|ji}i|�t�j�S)N�model)rr\�_invocation_params)r8�
openai_paramsr^r1r4rb�s
zAzureOpenAI._invocation_params�stop�Optional[List[str]]�kwargsrrcs>t�jdd|i|��}|j}d|d<|�d�}r||d<|S)z Get standard params for tracing.rdr(�ls_providerra�
ls_model_nameNr1)r\�_get_ls_paramsrb�get)r8rdrf�params�invocation_params�
model_namer^r1r4ri�szAzureOpenAI._get_ls_paramsrMcCr:)zReturn type of llm.r(r1r7r1r1r4�	_llm_type�r<zAzureOpenAI._llm_typecCs|j|jd�S)N�r)rror7r1r1r4�
lc_attributes�s�zAzureOpenAI.lc_attributes)r,r-)r,r6)r,r*)r,r)r,r[)r,r`)N)rdrerfrr,r)r,rM)�__name__�
__module__�__qualname__�__doc__rrr�__annotations__rrr
r"r$r%r&r)r+�classmethodr5�propertyr9r;rrZr]rbrirnrp�
__classcell__r1r1r^r4rsf

�
���
�
�H�r)�
__future__r�logging�typingrrrrrrr	r
r0�langchain_core.language_modelsr�langchain_core.utilsrr
�pydanticrrr�typing_extensionsrr�langchain_openai.llms.baser�	getLoggerrq�loggerrr1r1r1r4�<module>s(