o
    ưi                  	   @   s   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T er5d dlmZ d dl	mZmZ d	ed
ddddee fddZdee
ed f fddZdaeee
ed f  ed< dd Zde
ded fddZdS )    N)TYPE_CHECKINGDictOptionalType)verbose_logger)	CallTypes   )*)BaseTranslation)	ModelInfoUsagecustom_llm_providerusager   
model_infor   returnc                 C   s   | dkrddl m} |||dS | dkr ddlm} |||dS | dr1ddlm} |||dS | d	kr7d
S | dkrGddlm} |||dS dS )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   Z	anthropic)!get_cost_for_anthropic_web_search)r   r   Z	vertex_aiZ
perplexityg        ZxaiN)Zgemini.cost_calculatorr   Zanthropic.cost_calculationr   
startswithZ vertex_ai.gemini.cost_calculatorZxai.cost_calculator)r   r   r   r   r   Z%cost_per_web_search_request_vertex_ai r   L/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/__init__.pyget_cost_for_web_search_request   s   
r   r
   c                  C   s"  i } zt jt}|}t j|std | W S t |D ]\}}}dd |D |dd< t j|dkrd|v rt j	|t j|}d|
t jd }z2td	|  t|}t|d
rt|d
}	t|	tr| |	 td| dt|	   W q ty }
 ztd| d|
  W Y d}
~
qd}
~
w ty }
 ztd| d|
  W Y d}
~
qd}
~
ww qzddlm} | | tdt|  W n ty   td Y nw tdt|  dt|    W | S  ty }
 ztd|
  W Y d}
~
| S d}
~
w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 foundc                 S   s"   g | ]}| d s|dkr|qS )__Zbase_llm)r   ).0dr   r   r   
<listcomp>O   s   " z;discover_guardrail_translation_mappings.<locals>.<listcomp>NZ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walkbasenamerelpathreplacesep	importlibimport_modulehasattrgetattr
isinstancedictupdatelistkeysImportErrorerror	ExceptionZ<litellm.proxy._experimental.mcp_server.guardrail_translationr   len)Zdiscovered_mappingsZcurrent_dirZllms_dirrootdirsfilesrel_pathmodule_pathmoduleZmappingseZ"mcp_guardrail_translation_mappingsr   r   r   'discover_guardrail_translation_mappings6   sr   







r=   'endpoint_guardrail_translation_mappingsc                   C   s   t d u rt a t S )N)r>   r=   r   r   r   r   #load_guardrail_translation_mappings   s   r?   	call_typec                 C   s:   t du rt a | t vrtd|  dtt   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
    Nz6No guardrail translation mapping found for call_type: z. Available mappings: )r>   r=   
ValueErrorr0   r1   )r@   r   r   r   !get_guardrail_translation_mapping   s   
rB   )r)   r   typingr   r   r   r   Zlitellm._loggingr   Zlitellm.types.utilsr    Z<litellm.llms.base_llm.guardrail_translation.base_translationr
   r   r   strfloatr   r=   r>   __annotations__r?   rB   r   r   r   r   <module>   s6   
 
%
X	