
    h                         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rd 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Zd	ededee   fdZy)    )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                 "  K   | yt        | d      sy| j                  yd|v ryt        |dd      }t        |      }|||z  }|d|dt          z  }| j                  j                  d| ddt        j                  i 	       d{    y7 w)
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_loggerproxy_server_requestlitellm_debug_infoz

zLLM API call failed: ``High)messagelevel
alert_typealerting_metadata)hasattrr   getattrstrr   
send_alertr
   llm_exceptions)r   r   r   original_exceptionr   exception_strs         ]/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/router_utils/handle_error.pysend_llm_exception_alertr#      s     " &*,CD44</ 	 !35I4P*+M%++t/0M1MNOPPM
!
7
7
B
B(q9++	 C   s   BBBBmodelparent_otel_spanc                    K   t        j                  d| d       | j                  |      }| j                  j	                  ||      }t        | |       d{   }t        ||| j                  |      S 7 w)zV
    Raises a RouterRateLimitError if no deployment is found for the given model.
    z$get_available_deployment for model: z, No deployment available)
model_name)	model_idsr%   )r   r%   N)r$   cooldown_timeenable_pre_call_checkscooldown_list)r   infoget_model_idscooldown_cacheget_min_cooldownr	   r   r*   )r   r$   r%   r(   _cooldown_time_cooldown_lists         r"   #async_raise_no_deployment_exceptionr2   D   s      
.ug5NO (555GI,;;LL.> M N K 7) N  $6MM$	 	s   AA;A9A;N)typingr   r   r   r   litellm._loggingr   litellm.constantsr   &litellm.router_utils.cooldown_handlersr	   )litellm.types.integrations.slack_alertingr
   litellm.types.routerr   opentelemetry.tracer   _Spanlitellm.routerr   _RouterLitellmRouterdictr   r#   r2        r"   <module>rA      s    6 6 2 : @ 510MDMD**** *Z*36JRSW.r@   