
    i!                         d Z ddlmZ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 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 Batches API Handler
    )Any	CoroutineOptionalUnioncastN)AsyncOpenAIOpenAI)AsyncAzureOpenAIAzureOpenAI)CancelBatchRequestCreateBatchRequestRetrieveBatchRequest)LiteLLMBatch   )BaseAzureLLMc                       e Zd ZdZd fdZdedeeef   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eef      dee   dee	eeee	f   f   fdZdedeeef   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eef      dee   fdZdedeeef   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eef      dee   fdZ	 	 ddeeef   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eeeef      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    s/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/azure/batches/handler.pyr   zAzureBatchesAPI.__init__   s        create_batch_dataazure_clientc                    K    |j                   j                  di | d {   }t        di |j                         S 7 wN )batchescreater   
model_dump)r   r   r   responses       r   acreate_batchzAzureBatchesAPI.acreate_batch!   sD     
 5--44I7HII4h11344 J    AA A	_is_asyncapi_keyapi_baseapi_versiontimeoutmax_retriesclientlitellm_paramsc
           	      b   | j                  ||||||	xs i       }
|
t        d      |du r4t        |
t        t        f      st        d      | j                  ||
      S  t        t        t        t        f   |
      j                  j                  di |}t        di |j                         S )N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    )get_azure_openai_client
ValueError
isinstancer
   r   r%   r   r   r   r	   r!   r"   r   r#   )r   r'   r   r(   r)   r*   r+   r,   r-   r.   r   r$   s               r   create_batchzAzureBatchesAPI.create_batch)   s      ((#)/R ) 
 	 |  l-={,KL r  %%"3, &   Q4k612LAIIPPeSde4h11344r   retrieve_batch_datac                    K    |j                   j                  di | d {   }t        di |j                         S 7 wr   )r!   retriever   r#   )r   r7   r-   r$   s       r   aretrieve_batchzAzureBatchesAPI.aretrieve_batchQ   sB     
 100G3FGG4h11344 Hr&   c
           	      b   | j                  ||||||	xs i       }
|
t        d      |du r4t        |
t        t        f      st        d      | j                  ||
      S  t        t        t        t        f   |
      j                  j                  di |}t        di |j                         S )Nr0   r1   Tr2   )r7   r-   r    )r3   r4   r5   r
   r   r:   r   r   r   r	   r!   r9   r   r#   )r   r'   r7   r(   r)   r*   r+   r,   r-   r.   r   r$   s               r   retrieve_batchzAzureBatchesAPI.retrieve_batchY   s      ((#)/R ) 
 	 |  l-={,KL r  ''$7 (   S4k612LAIIRR 
!
 4h11344r   cancel_batch_datac                    K    |j                   j                  di | d {   }t        di |j                         S 7 wr   )r!   cancelr   r#   )r   r=   r-   r$   s       r   acancel_batchzAzureBatchesAPI.acancel_batch   sB     
 /..C1BCC4h11344 Dr&   c
           	      n   | j                  ||||||	xs i       }
|
t        d      |du r4t        |
t        t        f      st        d      | j                  ||
      S t        |
t        t        f      st        d       |
j                  j                  di |}t        di |j                         S )Nr0   r1   TziAzure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI. Make sure you passed an async client.)r=   r-   z]Azure client is not an instance of AzureOpenAI or OpenAI. Make sure you passed a sync client.r    )r3   r4   r5   r
   r   r@   r   r	   r!   r?   r   r#   )r   r'   r=   r(   r)   r*   r+   r,   r-   r.   r   r$   s               r   cancel_batchzAzureBatchesAPI.cancel_batch   s      ((#)/R ) 
 	 |  l-={,KL   %%"3L &  
 ,f(=>o  /<''..C1BC4h11344r   afterlimitc                 \   K   |j                   j                  ||       d {   }|S 7 w)NrC   rD   )r!   list)r   r-   rC   rD   r$   s        r   alist_batcheszAzureBatchesAPI.alist_batches   s/       ,,5,FF Gs   !,*,c           	         | j                  ||||	||
xs i       }|t        d      |du r5t        |t        t        f      st        d      | j                  |||      S |j                  j                  ||      }|S )Nr0   r1   Tr2   )r-   rC   rD   rF   )r3   r4   r5   r
   r   rH   r!   rG   )r   r'   r(   r)   r*   r+   r,   rC   rD   r-   r.   r   r$   s                r   list_batcheszAzureBatchesAPI.list_batches   s    " ((#)/R ) 
 	 |  l-={,KL r  %%#5 &    '',,5,Fr   )r   N)NN)NNNN)!__name__
__module____qualname____doc__r   r   r   r
   r   r   r%   boolr   strfloathttpxTimeoutintr   r	   dictr   r   r6   r   r:   r<   r   r@   rB   rH   rJ   __classcell__)r   s   @r   r   r      s   5-5 ,k9:5 
	5& )-&5&5 .&5 #	&5
 3-&5 c]&5 uemm+,&5 c]&5 +/DE
&5 !&5 
|YsC'=>>	?&5P515 &345 
	5& )-(5(5 2(5 #	(5
 3-(5 c](5 uemm+,(5 c](5 +/DE
(5 !(5T5-5 &345 
	5& )-,5,5 .,5 #	,5
 3-,5 c],5 uemm+,,5 c],5 +/DE
,5 !,5b  $#	&34 } }	"  $# )-'' #' 3-	'
 c]' uemm+,' c]' }' }' +/DE
' !'r   r   )rN   typingr   r   r   r   r   rR   openair   r	   litellm.llms.azure.azurer
   r   litellm.types.llms.openair   r   r   litellm.types.utilsr   common_utilsr   r   r    r   r   <module>r]      s;    9 8  & B 
 - 'Tl Tr   