o
    i                  
   @  s   d dl mZ d dlZd dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ zd dlmZ W n e ys Z! ze de!dZ![!ww G dd dee Z"dS )    )annotationsN)overload)AsyncOpenAI)ModelProfile)	UserError)cached_async_http_client)cohere_model_profile)deepseek_model_profile)grok_model_profile)meta_model_profile)mistral_model_profile)OpenAIJsonSchemaTransformerOpenAIModelProfileopenai_model_profile)Provider)AsyncAzureOpenAIu   Please install the `openai` package to use the Azure provider, you can use the `openai` optional group — `pip install "pydantic-ai-slim[openai]"`c                   @  s   e Zd ZdZed ddZed ddZed!d	d
Zd"ddZe	d#ddZ
e	dddddd$ddZ
ddddddd%ddZ
dS )&AzureProviderzzProvider for Azure OpenAI API.

    See <https://azure.microsoft.com/en-us/products/ai-foundry> for more information.
    returnstrc                 C  s   dS )Nazure selfr   r   a/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/providers/azure.pyname#   s   zAzureProvider.namec                 C  s   | j d usJ | j S N)	_base_urlr   r   r   r   base_url'   s   zAzureProvider.base_urlr   c                 C  s   | j S r   )_clientr   r   r   r   client,   s   zAzureProvider.client
model_nameModelProfile | Nonec                 C  sv   |  }tttttttd}| D ]$\}}||r6|dr(|t	|d  }||}t
td|  S qt|S )N)llamazmeta-deepseekz
mistralai-mistralzcohere-grok-)json_schema_transformer)lowerr   r	   r   r   r
   items
startswithendswithlenr   r   updater   )r   r    prefix_to_profileprefixprofile_funcprofiler   r   r   model_profile0   s"   


zAzureProvider.model_profileopenai_clientr   Nonec                C     d S r   r   )r   r3   r   r   r   __init__K   s   zAzureProvider.__init__N)azure_endpointapi_versionapi_keyhttp_clientr7   
str | Noner8   r9   r:   httpx.AsyncClient | Nonec                C  r5   r   r   )r   r7   r8   r9   r:   r   r   r   r6   N   s   )r7   r8   r9   r3   r:   AsyncAzureOpenAI | Nonec                C  s   |dur'|du sJ d|du sJ d|du sJ dt |j| _|| _dS |p-td}|s4td|s?dtjvr?td|sJd	tjvrJtd
|pPtdd}t	||||d| _t | jj| _dS )a  Create a new Azure provider.

        Args:
            azure_endpoint: The Azure endpoint to use for authentication, if not provided, the `AZURE_OPENAI_ENDPOINT`
                environment variable will be used if available.
            api_version: The API version to use for authentication, if not provided, the `OPENAI_API_VERSION`
                environment variable will be used if available.
            api_key: The API key to use for authentication, if not provided, the `AZURE_OPENAI_API_KEY` environment variable
                will be used if available.
            openai_client: An existing
                [`AsyncAzureOpenAI`](https://github.com/openai/openai-python#microsoft-azure-openai)
                client to use. If provided, `base_url`, `api_key`, and `http_client` must be `None`.
            http_client: An existing `httpx.AsyncClient` to use for making HTTP requests.
        Nz8Cannot provide both `openai_client` and `azure_endpoint`z5Cannot provide both `openai_client` and `http_client`z1Cannot provide both `openai_client` and `api_key`AZURE_OPENAI_ENDPOINTzeMust provide one of the `azure_endpoint` argument or the `AZURE_OPENAI_ENDPOINT` environment variableAZURE_OPENAI_API_KEYz]Must provide one of the `api_key` argument or the `AZURE_OPENAI_API_KEY` environment variableOPENAI_API_VERSIONz_Must provide one of the `api_version` argument or the `OPENAI_API_VERSION` environment variabler   )provider)r7   r9   r8   r:   )
r   r   r   r   osgetenvr   environr   r   )r   r7   r8   r9   r3   r:   r   r   r   r6   X   s6   
)r   r   )r   r   )r    r   r   r!   )r3   r   r   r4   )
r7   r;   r8   r;   r9   r;   r:   r<   r   r4   )r7   r;   r8   r;   r9   r;   r3   r=   r:   r<   r   r4   )__name__
__module____qualname____doc__propertyr   r   r   r2   r   r6   r   r   r   r   r      s.    
r   )#
__future__r   _annotationsrB   typingr   httpxopenair   pydantic_air   pydantic_ai.exceptionsr   pydantic_ai.modelsr   pydantic_ai.profiles.coherer   pydantic_ai.profiles.deepseekr	   pydantic_ai.profiles.grokr
   pydantic_ai.profiles.metar   pydantic_ai.profiles.mistralr   pydantic_ai.profiles.openair   r   r   pydantic_ai.providersr   r   ImportError_import_errorr   r   r   r   r   <module>   s4    