
    i              	           U d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
 ddl erd dlmZ d dl	mZmZ d	ed
ddddee   fdZdee
ed   f   fdZdaeee
ed   f      ed<   d Zde
ded   fdZy)    N)TYPE_CHECKINGDictOptionalType)verbose_logger)	CallTypes   )*)BaseTranslation)	ModelInfoUsagecustom_llm_providerusager   
model_infor   returnc                     | dk(  rddl m}  |||      S | dk(  rddlm}  |||      S | j	                  d      rddlm}  |||      S | d	k(  ry
| dk(  rddlm}  |||      S y)z
    Get the cost for a web search request for a given model.

    Args:
        custom_llm_provider: The custom LLM provider.
        usage: The usage object.
        model_info: The model info.
    geminir	   )cost_per_web_search_request)r   r   	anthropic)!get_cost_for_anthropic_web_search)r   r   	vertex_ai
perplexityg        xaiN)gemini.cost_calculatorr   anthropic.cost_calculationr   
startswith vertex_ai.gemini.cost_calculatorxai.cost_calculator)r   r   r   r   r   %cost_per_web_search_request_vertex_ais         f/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/__init__.pyget_cost_for_web_search_requestr!      s~     h&G*:NN		+Q0JeTT		'	'	4	
 55ZXX		, 		%D*:NN    r   c            
         i } 	 t         j                  j                  t              }|}t         j                  j	                  |      st        j                  d       | S t        j                  |      D ]S  \  }}}|D cg c]  }|j                  d      r|dk7  s| c}|dd t         j                  j                  |      dk(  sVd|v s[t         j                  j                  |t         j                  j                  |            }d|j                  t         j                  d      z   }	 t        j                  d	|        t        j                  |      }	t        |	d
      r_t!        |	d
      }
t#        |
t$              rC| j'                  |
       t        j                  d| dt)        |
j+                                       V 	 ddlm} | j'                  |       t        j                  dt)        |j+                                      t        j                  dt7        |        dt)        | j+                                       | S c c}w # t,        $ r&}t        j.                  d| d|        Y d}~d}~wt0        $ r&}t        j.                  d| d|        Y d}~5d}~ww xY w# t,        $ r t        j                  d       Y w xY w# t0        $ r#}t        j.                  d|        Y d}~| S d}~ww xY w)a;  
    Discover guardrail translation mappings by scanning the llms directory structure.

    Scans for modules with guardrail_translation_mappings dictionaries and aggregates them.

    Returns:
        Dict[CallTypes, Type[BaseTranslation]]: A dictionary mapping call types to their translation handler classes
    zllms directory not found__base_llmNguardrail_translationz__init__.pyzlitellm..z'Discovering guardrail translations in: guardrail_translation_mappingsz(Found guardrail_translation_mappings in z: zCould not import zError processing r   )r(   z-Loaded MCP guardrail translation mappings: %sz:MCP guardrail translation mappings not available; skippingzDiscovered z! guardrail translation mappings: z2Error discovering guardrail translation mappings: )ospathdirname__file__existsr   debugwalkr   basenamerelpathreplacesep	importlibimport_modulehasattrgetattr
isinstancedictupdatelistkeysImportErrorerror	Exception<litellm.proxy._experimental.mcp_server.guardrail_translationr(   len)discovered_mappingscurrent_dirllms_dirrootdirsfilesdrel_pathmodule_pathmodulemappingse"mcp_guardrail_translation_mappingss                r    'discover_guardrail_translation_mappingsrO   6   s    EGCWggooh/ww~~h'  !;<&& "$!2D$"&U$Qall4.@Q*_q$UDG   &*AA!U* 77??41JK(8+;+;BFFC+HH"((A+O '44[AF v'GH#*63S#T%h5/66x@*00"J;-WYZ^_g_l_l_nZoYp q5 "3J	  &&'IJ  ?7<<>? 	#1233TUYZmZrZrZtUuTvw	
 s V8 # "((+<[MA3)OP  "((+<[MA3)OP  	  L	  WQRSQTUVVWs   AK !K  III!(K 
K A K 0BIK AJ1 ;K K 	J.I<6K <J.J)#K )J..K 1KK KK 	LK<<L'endpoint_guardrail_translation_mappingsc                  .    t         
t               a t         S )N)rP   rO    r"   r    #load_guardrail_translation_mappingsrS      s    .635 	0 32r"   	call_typec           	          t         
t               a | t         vr,t        d|  dt        t         j	                                      t         |    S )aO  
    Get the guardrail translation handler for a given call type.

    Args:
        call_type: The type of call (e.g., completion, acompletion, anthropic_messages)

    Returns:
        The translation handler class for the given call type

    Raises:
        ValueError: If no translation mapping exists for the given call type
    z6No guardrail translation mapping found for call_type: z. Available mappings: )rP   rO   
ValueErrorr;   r<   )rT   s    r    !get_guardrail_translation_mappingrW      sb      /635 	0
 ??DYK P##'(O(T(T(V#W"XZ
 	
 39==r"   )r4   r)   typingr   r   r   r   litellm._loggingr   litellm.types.utilsr    <litellm.llms.base_llm.guardrail_translation.base_translationr   r   r   strfloatr!   rO   rP   __annotations__rS   rW   rR   r"   r    <module>r`      s     	 6 6 + )  5""%,":E"e_"JRD*+	+,Rp 	 (D*+	+,* 	
3> >tDU?V >r"   