
    g                      l    d Z ddlmZmZmZmZ ddlZddlZddlm	Z	m
Z
 ddlmZmZmZmZ  G d d      Zy)z
Azure Batches API Handler
    )Any	CoroutineOptionalUnionN)AsyncAzureOpenAIAzureOpenAI)BatchCancelBatchRequestCreateBatchRequestRetrieveBatchRequestc                       e Zd ZdZd fdZ	 	 	 ddee   dee   deee	j                  f   dee   dee   d	eeeef      d
edeeeef      fdZdededefdZ	 dd
ededee   dee   dee   deee	j                  f   dee   d	eeeef      deeeeeef   f   fdZded	edefdZ	 dd
ededee   dee   dee   deee	j                  f   dee   d	ee   fdZded	edefdZ	 dd
ededee   dee   dee   deee	j                  f   dee   d	ee   fdZ	 	 dd	edee   dee   fdZ	 	 	 dd
edee   dee   dee   deee	j                  f   dee   dee   dee   d	ee   fdZ xZS )AzureBatchesAPIz
    Azure methods to support for batches
    - create_batch()
    - retrieve_batch()
    - cancel_batch()
    - list_batch()
    returnc                 "    t         |           y N)super__init__)self	__class__s    W/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/azure/batches/handler.pyr   zAzureBatchesAPI.__init__   s        api_keyapi_basetimeoutmax_retriesapi_versionclient	_is_asyncc                    t               }d }	|ti }
|j                         D ]*  \  }}|dk(  s
|dk(  s|dk(  r|dk(  r|||
d<   #|&||
|<   , d|
vrt        j                  |
d<   |du rt	        di |
}	|	S t        di |
}	|	S |}	|	S )	Nr   r   r   r   azure_endpointr   T )localsitemslitellmAZURE_DEFAULT_API_VERSIONr   r   )r   r   r   r   r   r   r   r   received_argsopenai_clientdatakvs                r   get_azure_openai_clientz'AzureBatchesAPI.get_azure_openai_client   s     HL>D%++-1;!x-13C*_-.D)*]DG . D(&-&G&G]#D  0 84 8 	 !, 3d 3  #Mr   create_batch_dataazure_clientc                 Z   K    |j                   j                  di | d {   }|S 7 wNr!   )batchescreate)r   r,   r-   responses       r   acreate_batchzAzureBatchesAPI.acreate_batch?   s2     
 5--44I7HII J    +)+c	           	          | j                  |||||||      }	|	t        d      |du r.t        |	t              st        d      | j	                  ||	      S  |	j
                  j                  di |}
|
S )N)r   r   r   r   r   r   r   jOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment.T\OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client.)r,   r-   r!   )r+   
ValueError
isinstancer   r3   r0   r1   )r   r   r,   r   r   r   r   r   r   r-   r2   s              r   create_batchzAzureBatchesAPI.create_batchG   s     ((!''# )  	 |  l,<= r  %%"3, &   /<''..C1BCr   retrieve_batch_datac                 Z   K    |j                   j                  di | d {   }|S 7 wr/   )r0   retrieve)r   r;   r   r2   s       r   aretrieve_batchzAzureBatchesAPI.aretrieve_batchm   s0     
 100G3FGG Hr4   c	           	          | j                  |||||||      }	|	t        d      |du r.t        |	t              st        d      | j	                  ||	      S  |	j
                  j                  di |}
|
S )Nr   r   r   r   r   r   r   r6   Tr7   )r;   r   r!   )r+   r8   r9   r   r>   r0   r=   )r   r   r;   r   r   r   r   r   r   r-   r2   s              r   retrieve_batchzAzureBatchesAPI.retrieve_batchu   s     ((!''# )  	 |  l,<= r  ''$7 (   1<''00G3FGr   cancel_batch_datac                 Z   K    |j                   j                  di | d {   }|S 7 wr/   )r0   cancel)r   rB   r   r2   s       r   acancel_batchzAzureBatchesAPI.acancel_batch   s0     
 /..C1BCC Dr4   c	           	          | j                  |||||||      }	|	t        d       |	j                  j                  di |}
|
S )Nr@   r6   r!   )r+   r8   r0   rD   )r   r   rB   r   r   r   r   r   r   r-   r2   s              r   cancel_batchzAzureBatchesAPI.cancel_batch   sl     ((!''# )  	 |  /<''..C1BCr   afterlimitc                 \   K   |j                   j                  ||       d {   }|S 7 w)NrH   rI   )r0   list)r   r   rH   rI   r2   s        r   alist_batcheszAzureBatchesAPI.alist_batches   s/       ,,5,FF Gs   !,*,c
           	          | j                  ||||||	|      }
|
t        d      |du r/t        |
t              st        d      | j	                  |
||      S |
j
                  j                  ||      }|S )N)r   r   r   r   r   r   r   r6   Tr7   )r   rH   rI   rK   )r+   r8   r9   r   rM   r0   rL   )r   r   r   r   r   r   r   rH   rI   r   r-   r2   s               r   list_batcheszAzureBatchesAPI.list_batches   s     ((!''# )  	 |  l,<= r  %%#5 &    '',,5,Fr   )r   N)NNFr   )NN)NNN)__name__
__module____qualname____doc__r   r   strr   floathttpxTimeoutintr   r   boolr+   r   r	   r3   r   r   r:   r   r>   rA   r
   rE   rG   rM   rO   __classcell__)r   s   @r   r   r      sq    &*AE# 3- uemm+,	
 c] c] {,<<=>  
%%556	7@- ' 
	" BF$$ .$ #	$
 3-$ c]$ uemm+,$ c]$ {,<<=>$ 
uiS%00	1$L1 ! 
	" )-$$ 2$ #	$
 3-$ c]$ uemm+,$ c]$ %$L- ! 
	" )- . #	
 3- c] uemm+, c] %@  $#	  } }	"  $#(,%% #% 3-	%
 c]% uemm+,% c]% }% }% %%r   r   )rS   typingr   r   r   r   rV   r$   litellm.llms.azure.azurer   r   litellm.types.llms.openair	   r
   r   r   r   r!   r   r   <module>r^      s1    3 2   B [ [r   