Ë
    uPêjÒ  ã                   óJ   — d Z ddlmZ ddlmZ ddlmZ dededee	e	f   fd„Z
y	)
zg
Helper util for handling perplexity-specific cost calculation
- e.g.: citation tokens, search queries
é    )ÚFinal)ÚUsage)Úget_model_infoÚmodelÚusageÚreturnc                 óÊ  — t        |dd«      }d}t        |t        «      r|j                  d«      }n1t        |t        t
        f«      rt        |t        «      st        |«      }|�dt        |«      fS t        | d¬«      }ddt        t
        z  dz  t        z  dt
        d	t
        fd
„} ||j                  d«      «      }|j                  xs d|z  }t        |dd«      xs d}|j                  d«      }	|dkD  r|	� ||	«      }
|||
z  z  } ||j                  d«      «      }t        |dd«      xs d}|dk(  r3t        |d«      r'|j                  rt        |j                  dd«      xs d}|j                  d«      }|dkD  r3|�1t        d|j                  xs d|z
  «      }||z  }|| ||«      z  z  }n|j                  xs d|z  }d}t        |d«      r'|j                  rt        |j                  dd«      xs d}|j                  d«      xs |j                  d«      }|dkD  r=|�;t        |t        «      r ||j                  dd«      «      }n ||«      }||z  }||z  }||fS )aW  
    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 perplexity-specific usage information

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd
    ÚcostNÚ
total_costç        Ú
perplexity)r   Úcustom_llm_providerÚvalueÚdefaultr   c                 óP   — | €|S 	 t        | «      S # t        t        f$ r |cY S w xY w)z@Safely cast a value to float with proper type handling for mypy.)ÚfloatÚ
ValueErrorÚ	TypeError)r   r   s     úl/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/perplexity/cost_calculator.pyÚ_safe_float_castz(cost_per_token.<locals>._safe_float_cast*   s4   € àˆ=ØˆNð	Ü˜“<ÐøÜœIÐ&ò 	ØŠNð	ús   †
 ‘%¤%Úinput_cost_per_tokenr   Úcitation_tokensÚcitation_cost_per_tokenÚoutput_cost_per_tokenÚreasoning_tokensÚcompletion_tokens_detailsÚoutput_cost_per_reasoning_tokenÚprompt_tokens_detailsÚweb_search_requestsÚsearch_queries_cost_per_queryÚsearch_context_cost_per_queryÚsearch_context_size_low)r   )ÚgetattrÚ
isinstanceÚdictÚgetÚintr   Úboolr   ÚstrÚobjectÚprompt_tokensÚhasattrr   ÚmaxÚcompletion_tokensr   )r   r   Ú	cost_infor   Ú
model_infor   r   Úprompt_costr   Úcitation_cost_valuer   r   r   Úreasoning_cost_valueÚnon_reasoning_completion_tokensÚcompletion_costÚnum_search_queriesÚsearch_cost_valueÚsearch_cost_per_queryÚsearch_costs                       r   Úcost_per_tokenr:      s¼  € ô ˜u f¨dÓ3€IØ#€JÜ�)œTÔ"Ø—]‘] <Ó0‰
Ü	�I¤¤U˜|Ô	,´ZÀ	Ì4Ô5PÜ˜9Ó%ˆ
ØÐð ”U˜:Ó&Ð'Ð'ô '¨UÈÔU€Jñ¤¤e¡¨dÑ 2´VÑ ;ð Äeð ÔV[ó ñ #3°:·>±>ÐBXÓ3YÓ"ZÐØ×-Ñ-Ò2°Ð6JÑJ€Kô % UÐ,=¸qÓAÒFÀQ€OØ!+§¡Ð0IÓ!JÐØ˜ÒÐ2Ð>Ù)9Ð:MÓ)NÐØ�Ð)@Ñ@Ñ@ˆñ $4°J·N±NÐCZÓ4[Ó#\Ðä˜uÐ&8¸!Ó<ÒAÀÐØ˜1Ò¤¨Ð0KÔ!LÐQV×QpÒQpÜ" 5×#BÑ#BÐDVÐXYÓZÒ_Ð^_Ðà",§.¡.Ð1RÓ"SÐð ˜!ÒÐ 4Ð @Ü14°Q¸×9PÑ9PÒ9UÐTUÐYiÑ8iÓ1jÐ'Ø!@ÐCXÑ!XˆØÐ+Ñ.>Ð?SÓ.TÑTÑT‰à ×2Ñ2Ò7°aÐ;PÑPˆð ÐÜˆuÐ-Ô.°5×3NÒ3NÜ$ U×%@Ñ%@ÐBWÐYZÓ[Ò`Ð_`Ðð  *Ÿ~™~Ð.MÓNò  ÐR\×R`ÑR`Ø'óSÐð ˜AÒÐ"3Ð"?äÐ'¬Ô.ñ %5Ð5F×5JÑ5JÐKdÐfgÓ5hÓ$iÑ!á$4Ð5FÓ$GÐ!Ø/Ð2GÑGˆà˜;Ñ&ˆà˜Ð'Ð'ó    N)Ú__doc__Útypingr   Úlitellm.types.utilsr   Úlitellm.utilsr   r)   Útupler   r:   © r;   r   ú<module>rB      s<   ðñõ
 å %Ý (ð\(˜#ð \( eð \(°°e¸U°lÑ0Cô \(r;   