o
    ưi                     @   s   d Z ddlZddlmZmZmZmZmZ ddlZddl	m
Z
 ddlmZmZ er/ddlmZ neZddlmZ d	d
lmZ G dd dZdS )z
Anthropic Batches API Handler
    N)TYPE_CHECKINGAny	CoroutineOptionalUnion)get_async_httpx_client)LiteLLMBatchLlmProvidersLogging   )AnthropicModelInfo   )AnthropicBatchesConfigc                   @   s   e Zd ZdZdd Z	ddedee dee deee	j
f d	ee d
ee defddZ	ddededee dee deee	j
f d	ee d
ee deeeeeef f fddZdS )AnthropicBatchesHandlerz
    Handler for Anthropic Message Batches API.
    
    Supports:
    - retrieve_batch() - Retrieve batch status and information
    c                 C   s   t  | _t | _d S N)r   anthropic_model_infor   provider_config)self r   ]/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/anthropic/batches/handler.py__init__    s   z AnthropicBatchesHandler.__init__Nbatch_idapi_baseapi_keytimeoutmax_retrieslogging_objreturnc              	      s   |p| j |}|p| j  }|std|du r.ddlm} |dg dddd| dd	}| jj||i i d
}| jji dg i i ||d}	|j	||||	i dd t
tjd}
|
j||	dI dH }|  | jjd||i dS )a  
        Async: Retrieve a batch from Anthropic.
        
        Args:
            batch_id: The batch ID to retrieve
            api_base: Anthropic API base URL
            api_key: Anthropic API key
            timeout: Request timeout
            max_retries: Max retry attempts (unused for now)
            logging_obj: Optional logging object
            
        Returns:
            LiteLLMBatch: Batch information in OpenAI format
        zMissing Anthropic API KeyNr   r
   zanthropic/unknownFZbatch_retrieveZbatch_retrieve_)modelmessagesstreamZ	call_type
start_timeZlitellm_call_idZfunction_id)r   r   optional_paramslitellm_params )headersr   r    r#   r$   r   r   )r   r&   Zcomplete_input_dict)inputr   Zadditional_args)Zllm_provider)urlr&   )r   Zraw_responser   r$   )r   Zget_api_baseZget_api_key
ValueError*litellm.litellm_core_utils.litellm_loggingr   r   Zget_retrieve_batch_urlZvalidate_environmentZpre_callr   r	   Z	ANTHROPICgetraise_for_statusZ!transform_retrieve_batch_response)r   r   r   r   r   r   r   ZLiteLLMLoggingObjClassZretrieve_urlr&   Zasync_clientresponser   r   r   aretrieve_batch$   sf   

z'AnthropicBatchesHandler.aretrieve_batch	_is_asyncc              
   C   s6   |r| j ||||||dS t| j ||||||dS )a  
        Retrieve a batch from Anthropic.
        
        Args:
            _is_async: Whether to run asynchronously
            batch_id: The batch ID to retrieve
            api_base: Anthropic API base URL
            api_key: Anthropic API key
            timeout: Request timeout
            max_retries: Max retry attempts (unused for now)
            logging_obj: Optional logging object
            
        Returns:
            LiteLLMBatch or Coroutine: Batch information in OpenAI format
        )r   r   r   r   r   r   )r.   asynciorun)r   r/   r   r   r   r   r   r   r   r   r   retrieve_batch{   s&   	z&AnthropicBatchesHandler.retrieve_batchr   )__name__
__module____qualname____doc__r   strr   r   floathttpxTimeoutintLiteLLMLoggingObjr   r.   boolr   r   r2   r   r   r   r   r      sJ    
_	r   )r6   r0   typingr   r   r   r   r   r9   Z&litellm.llms.custom_httpx.http_handlerr   Zlitellm.types.utilsr   r	   r*   r   r<   Zcommon_utilsr   Ztransformationr   r   r   r   r   r   <module>   s    