o
    ưig                     @   s   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mZ ddlmZ de
ded	 fd
dZ	ddededee deeef fddZ	ddedee dedeeef fddZ		ddededee dee def
ddZdS )zR
Helper util for handling openai-specific cost calculation
- e.g.: prompt caching
    )LiteralOptionalTuple)verbose_loggergeneric_cost_per_token)	CallTypes	ModelInfoUsage)get_model_info	call_typereturn)cost_per_tokencost_per_secondc                 C   s   | t jks
| t jkrdS dS )Nr   r   )r   ZatranscriptionZtranscription)r    r   [/home/app/Keep/.python/lib/python3.10/site-packages/litellm/llms/openai/cost_calculation.pycost_router   s   r   Nmodelusageservice_tierc                 C   s   t | |d|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   r   r   r   r   r   r      s   r           r   durationc                 C   s   t | |pdd}d}d}d|v r1|d dur1td|  d|d d|  |d | }||fS d	|v rT|d	 durTtd|  d
|d	 d|  |d	 | }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   r   output_cost_per_secondN
For model= - output_cost_per_second: ; duration: Zinput_cost_per_secondz - input_cost_per_second: )r   r   debugget)r   r   r   
model_infoZprompt_costZcompletion_costr   r   r   r   V   s(   r   duration_secondsr!   c                 C   s   |du rt | |p	dd}|d}|dur'td|  d| d|  || S |d}|durBtd|  d	| d|  || S td
|  d dS )a7  
    Calculates the cost for video generation based on duration in seconds.

    Input:
        - model: str, the model name without provider prefix
        - duration_seconds: float, the duration of the generated video in seconds
        - custom_llm_provider: str, the custom llm provider
        - model_info: Optional[dict], deployment-level model info containing
            custom video pricing. When provided, skips the global
            get_model_info() lookup so that deployment-specific pricing is used.

    Returns:
        float - total_cost_in_usd
    Nr   r   Z output_cost_per_video_per_secondr   z% - output_cost_per_video_per_second: r   r   r   z*No cost information found for video model z<. Please add pricing to model_prices_and_context_window.jsonr   )r   r    r   r   warning)r   r"   r   r!   Zvideo_cost_per_secondr   r   r   r   video_generation_cost   s(   


r$   )N)r   )NN)__doc__typingr   r   r   Zlitellm._loggingr   Z.litellm.litellm_core_utils.llm_cost_calc.utilsr   Zlitellm.types.utilsr   r	   r
   Zlitellm.utilsr   r   strfloatr   r   r$   r   r   r   r   <module>   sP    

B

0