
    h                         d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZ de
ded	   fd
Zdededeeef   fdZ	 ddedee   dedeeef   fdZy)zR
Helper util for handling openai-specific cost calculation
- e.g.: prompt caching
    )LiteralOptionalTuple)verbose_loggergeneric_cost_per_token)	CallTypesUsage)get_model_info	call_typereturn)cost_per_tokencost_per_secondc                 R    | t         j                  k(  s| t         j                  k(  ryy)Nr   r   )r	   atranscriptiontranscription)r   s    `/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/llms/openai/cost_calculation.pycost_routerr      s#    I,,,	Y=T=T0T     modelusagec                     t        | |d      S )aO  
    Calculates the cost per token for a given model, prompt tokens, and completion tokens.

    Input:
        - model: str, the model name without provider prefix
        - usage: LiteLLM Usage block, containing anthropic caching information

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    openai)r   r   custom_llm_providerr   )r   r   s     r   r   r      s     "5h r   r   durationc                 8   t        | |xs d      }d}d}d|v r>|d   9t        j                  d|  d|j                  d       d|        |d   |z  }||fS d|v r<|d   7t        j                  d|  d	|j                  d       d|        |d   |z  }d}||fS )
a  
    Calculates the cost per second for a given model, prompt tokens, and completion tokens.

    Input:
        - model: str, the model name without provider prefix
        - custom_llm_provider: str, the custom llm provider
        - duration: float, the duration of the response in seconds

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    r   )r   r           output_cost_per_secondz
For model=z - output_cost_per_second: z; duration: input_cost_per_secondz - input_cost_per_second: )r   r   debugget)r   r   r   
model_infoprompt_costcompletion_costs         r   r   r   Q   s      )<)HJ KO 	!J./0<::>>Jb;c:ddpqypz{	
 %%=>I '' 	 :-./;9*..I`:a9bbnownxy	
 !!89HD''r   N)r   )__doc__typingr   r   r   litellm._loggingr   .litellm.litellm_core_utils.llm_cost_calc.utilsr   litellm.types.utilsr	   r
   litellm.utilsr   r   strfloatr   r    r   r   <module>r.      s   
 , + + Q 0 ( 9  1T)U  # e eUl0C z GJ)()(%-c])(>C)(
5%<)(r   