
    hY                         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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)AsyncAzureOpenAIAzureOpenAI)BatchCancelBatchRequestCreateBatchRequestRetrieveBatchRequest)LiteLLMBatch   )BaseAzureLLMc                       e Zd ZdZd 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   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   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   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   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    ^/var/www/Befach/backend/env/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
           	      <   | j                  ||||||	xs i       }
|
t        d      |du r.t        |
t              st        d      | j	                  ||
      S  t        t        |
      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#   s               r   create_batchzAzureBatchesAPI.create_batch)   s     ((#)/R ) 
 	 |  l,<= r  %%"3, &   B4\2::AAVDUV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   r6   r,   r#   s       r   aretrieve_batchzAzureBatchesAPI.aretrieve_batchO   sB     
 100G3FGG4h11344 Hr%   c
           	      <   | j                  ||||||	xs i       }
|
t        d      |du r.t        |
t              st        d      | j	                  ||
      S  t        t        |
      j                  j                  di |}t        di |j                         S )Nr/   r0   Tr1   )r6   r,   r   )r2   r3   r4   r   r9   r   r	   r    r8   r   r"   )r   r&   r6   r'   r(   r)   r*   r+   r,   r-   r   r#   s               r   retrieve_batchzAzureBatchesAPI.retrieve_batchW   s     ((#)/R ) 
 	 |  l,<= r  ''$7 (   D4\2::CC 
!
 4h11344r   cancel_batch_datac                 Z   K    |j                   j                  di | d {   }|S 7 wr   )r    cancel)r   r<   r,   r#   s       r   acancel_batchzAzureBatchesAPI.acancel_batch   s0     
 /..C1BCC Ds    +)+c
           	          | j                  ||||||	xs i       }
|
t        d       |
j                  j                  di |}|S )Nr/   r0   r   )r2   r3   r    r>   )r   r&   r<   r'   r(   r)   r*   r+   r,   r-   r   r#   s               r   cancel_batchzAzureBatchesAPI.cancel_batch   sn     ((#)/R ) 
 	 |  /<''..C1BCr   afterlimitc                 \   K   |j                   j                  ||       d {   }|S 7 w)NrB   rC   )r    list)r   r,   rB   rC   r#   s        r   alist_batcheszAzureBatchesAPI.alist_batches   s/       ,,5,FF Gs   !,*,c           	          | j                  ||||	||
xs i       }|t        d      |du r/t        |t              st        d      | j	                  |||      S |j
                  j                  ||      }|S )Nr/   r0   Tr1   )r,   rB   rC   rE   )r2   r3   r4   r   rG   r    rF   )r   r&   r'   r(   r)   r*   r+   rB   rC   r,   r-   r   r#   s                r   list_batcheszAzureBatchesAPI.list_batches   s     ((#)/R ) 
 	 |  l,<= r  %%#5 &    '',,5,Fr   )r   N)NN)NNNN) __name__
__module____qualname____doc__r   r   r   r   r$   boolr   strr   floathttpxTimeoutintr	   dictr   r   r5   r   r9   r;   r   r
   r?   rA   rG   rI   __classcell__)r   s   @r   r   r      s   5-5 '5 
	5" BF)-$5$5 .$5 #	$5
 3-$5 c]$5 uemm+,$5 c]$5 {,<<=>$5 !$5 
|YsC'=>>	?$5L515 !5 
	5" )-)-&5&5 2&5 #	&5
 3-&5 c]&5 uemm+,&5 c]&5 %&5 !&5P- ! 
	" )-)- . #	
 3- c] uemm+, c] % !@  $#	  } }	"  $#(,)-%% #% 3-	%
 c]% uemm+,% c]% }% }% %% !%r   r   )rM   typingr   r   r   r   r   rQ   litellm.llms.azure.azurer   r	   litellm.types.llms.openair
   r   r   r   litellm.types.utilsr   common_utilsr   r   r   r   r   <module>r[      s8    9 8  B  - '}l }r   