o
    ưi                     @   s   d dl mZmZmZ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 erAd dlmZ d dlmZ eZeeef ZneZeZd	ed
edefddZd	ededee fddZdS )    )TYPE_CHECKINGAnyOptionalUnion)verbose_router_logger)MAX_EXCEPTION_MESSAGE_LENGTH)/_async_get_cooldown_deployments_with_debug_info)	AlertType)RouterRateLimitError)Span)Routerlitellm_router_instancerequest_kwargserror_traceback_strc                    s   | du rdS t | dsdS | jdu rdS d|v rdS t|dd}t|}|dur-||7 }|d|dt  7 }| jjd| ddtji d	I dH  dS )
ac  
    Only runs if router.slack_alerting_logger is set
    Sends a Slack / MS Teams alert for the LLM API call failure. Only if router.slack_alerting_logger is set.

    Parameters:
        litellm_router_instance (_Router): The LitellmRouter instance.
        original_exception (Any): The original exception that occurred.

    Returns:
        None
    Nslack_alerting_loggerZproxy_server_requestlitellm_debug_infoz

zLLM API call failed: ``ZHigh)messagelevelZ
alert_typeZalerting_metadata)hasattrr   getattrstrr   Z
send_alertr	   Zllm_exceptions)r   r   r   Zoriginal_exceptionr   Zexception_str r   X/home/app/Keep/.python/lib/python3.10/site-packages/litellm/router_utils/handle_error.pysend_llm_exception_alert   s(   


r   modelparent_otel_spanc                    s|   t d| d | j|d}| jj||d}t| |dI dH }t d| d|  d	d
 |p2g D }t||| j|dS )zV
    Raises a RouterRateLimitError if no deployment is found for the given model.
    z$get_available_deployment for model: z, No deployment available)Z
model_name)	model_idsr   )r   r   NzNo deployment found for model: z!, cooldown_list with debug info: c                 S   s   g | ]}|d  qS )r   r   ).0Zcooldown_modelr   r   r   
<listcomp>Y   s    z7async_raise_no_deployment_exception.<locals>.<listcomp>)r   Zcooldown_timeenable_pre_call_checksZcooldown_list)r   infoZget_model_idsZcooldown_cacheZget_min_cooldownr   r
   r    )r   r   r   r   Z_cooldown_timeZ_cooldown_listZcooldown_list_idsr   r   r   #async_raise_no_deployment_exceptionD   s,   
r"   N)typingr   r   r   r   Zlitellm._loggingr   Zlitellm.constantsr   Z&litellm.router_utils.cooldown_handlersr   Z)litellm.types.integrations.slack_alertingr	   Zlitellm.types.routerr
   Zopentelemetry.tracer   _SpanZlitellm.routerr   Z_RouterZLitellmRouterdictr   r   r"   r   r   r   r   <module>   s6    
-