o
    ưi                     @   sp   d Z ddlmZmZmZ erddlmZmZ 	ddedddee d	ee	e	f fd
dZ
ddddd	e	fddZdS )zi
This file is used to calculate the cost of the Gemini API.

Handles the context caching for Gemini API.
    )TYPE_CHECKINGOptionalTuple)	ModelInfoUsageNmodelusager   service_tierreturnc                 C   s   ddl m} || |d|dS )z
    Calculates the cost per token for a given model, prompt tokens, and completion tokens.

    Follows the same logic as Anthropic's cost per token calculation.
    r   )generic_cost_per_tokengemini)r   r   Zcustom_llm_providerr	   )Z.litellm.litellm_core_utils.llm_cost_calc.utilsr   )r   r   r	   r    r   Z/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/gemini/cost_calculator.pycost_per_token   s   r   
model_infor   c                 C   sd   ddl m} d}d}| dur*| jdur*t| j|r*t| jdr*| jjdur*| jj}nd}|| }|S )zm
    Calculates the cost per web search request for a given model, prompt tokens, and completion tokens.
    r   )PromptTokensDetailsWrappergQ?Nweb_search_requests)litellm.types.utilsr   Zprompt_tokens_details
isinstancehasattrr   )r   r   r   cost_per_web_search_requestZnumber_of_web_search_requestsZ
total_costr   r   r   r      s   



r   )N)__doc__typingr   r   r   r   r   r   strfloatr   r   r   r   r   r   <module>   s    

