Ë
    uPêjÝ&  ã                   ó<  — U d dl mZmZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
mZ 	 	 g d¢Zeed<   ded	ed
ed   ez  ded   fd„Z	 	 	 	 dded	edededz  dedz  dedz  dedz  deeef   fd„Zde
dedeeef   fd„Z	 	 dded	edededz  dedz  deeef   fd„Zy)é    )ÚFinalÚLiteralN)Úverbose_logger)Ú_is_above_128kÚgeneric_cost_per_tokenÚ#get_vertex_regional_endpoint_uplift)Ú	ModelInfoÚUsage)zgemini-1.0-proz
gemini-proúgemini-2Úmodels_without_dynamic_pricingÚmodelÚcustom_llm_providerÚ	call_type)Ú	embeddingÚ
aembeddingÚreturn)Úcost_per_characterÚcost_per_tokenc                 óp   — |dk(  rd| v s,d| v s(d| v s$d| v s d| v sd| v s|dk(  r
|dk(  s|d	k(  s	|dk(  rd
| v ryy)z¦
    Route the cost calc to the right place, based on model/call_type/etc.

    Returns
        - str, the specific google cost calc function it should route to.
    Ú	vertex_aiÚclaudeÚllamaÚmistralÚjambaÚ	codestralÚgemmar   r   r   r   r   © )r   r   r   s      úk/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/vertex_ai/cost_calculator.pyÚcost_routerr      si   € ð 	˜{Ò*à˜ÑØ˜%ÑØ˜EÑ!Ø˜%ÑØ˜eÑ#Ø˜%Ñà +Ò-Ø˜+Ò%¨°lÒ)BØ +Ò-Ø˜5Ñ àØó    ÚusageÚprompt_charactersÚcompletion_charactersÚservice_tierÚvertex_locationc                 ó  — t        j                  | |¬«      }|€t        | |||¬«      \  }}	nU	 t        |dz  ¬«      r'| t        vrd|v r|d   €J d| › d|› �«       ‚||d   z  }nd	|v r|d	   €J d| › d
|› �«       ‚||d	   z  }|€t        | |||¬«      \  }	}na|j                  }	 t        |dz  ¬«      r'| t        vrd|v r|d   €J d| › d|› �«       ‚||d   z  }nd|v r|d   €J d| › d|› �«       ‚||d   z  }t        ||«      }||z  ||z  fS # t
        $ r2}
t        j                  d|
«       t        | |||¬«      \  }}	Y d}
~
ŒÂd}
~
ww xY w# t
        $ r2}
t        j                  d|
«       t        | |||¬«      \  }	}Y d}
~
ŒŠd}
~
ww xY w)aK  
    Calculates the cost per character for a given VertexAI model, input messages, and response object.

    Input:
        - model: str, the model name without provider prefix
        - custom_llm_provider: str, "vertex_ai-*"
        - prompt_characters: float, the number of input characters
        - completion_characters: float, the number of output characters
        - service_tier: optional tier derived from Gemini trafficType
          ("priority" for ON_DEMAND_PRIORITY, "flex" for FLEX/batch).
        - vertex_location: the Vertex AI location serving the request; non-global
          locations apply the model's regional-endpoint uplift multiplier

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd

    Raises:
        Exception if model requires >128k pricing, but model cost not mapped
    ©r   r   N)r   r   r!   r$   é   ©ÚtokensÚ*input_cost_per_character_above_128k_tokenszmodel info for model=za does not have 'input_cost_per_character_above_128k_tokens'-pricing for > 128k tokens
model_info=Úinput_cost_per_characterz= does not have 'input_cost_per_character'-pricing
model_info=zslitellm.litellm_core_utils.llm_cost_calc.google.py::cost_per_character(): Exception occured - %s
Defaulting to NoneÚ+output_cost_per_character_above_128k_tokenszP does not have 'output_cost_per_character_above_128k_tokens' pricing
model_info=Úoutput_cost_per_characterz> does not have 'output_cost_per_character'-pricing
model_info=)
ÚlitellmÚget_model_infor   r   r   Ú	Exceptionr   ÚdebugÚcompletion_tokensr   )r   r   r!   r"   r#   r$   r%   Ú
model_infoÚprompt_costÚ_ÚeÚcompletion_costr3   Úvertex_uplifts                 r   r   r   =   s›  € ô: ×'Ñ'¨eÐI\Ô]€Jð Ð Ü'ØØ 3ØØ%ô	
‰ˆ‘Qð	äÐ&7¸!Ñ&;Õ<ØÔ!?Ñ?ð AÀJÑNØ"Ð#OÑPÐ\ðð ,¨E¨7ð  3Uð  V`ð  Uað  bó	ð]ð
 0°*Ð=iÑ2jÑj‘ð /°*Ñ<ÀÐLfÑAgÐAsðð ,¨E¨7Ð2pÐq{Ðp|Ð}óØsð 0°*Ð=WÑ2XÑX�ð Ð$Ü+ØØ 3ØØ%ô	
Ñˆ‰?ð $)×#:Ñ#:Ðð	äÐ&;¸aÑ&?Õ@ØÔ!?Ñ?ð BÀZÑOØ"Ð#PÑQÐ]ðð ,¨E¨7ð  3Dð  EOð  DPð  Qó	ð^ð
 #4°jÐAnÑ6oÑ"o‘ð 0°:Ñ=À*ÐMhÑBiÐBuðð ,¨E¨7Ð2qÐr|Ðq}Ð~óØuð #8¸*ÐE`Ñ:aÑ"a�ô ?¸zÈ?Ó[€MØ˜Ñ&¨¸-Ñ(GÐGÐGøôm ò 
	Ü× Ñ ð GØôô ,ØØ$7ØØ)ô	‰NˆK�ûð
	ûôR ò 
	Ü× Ñ ð GØôô "0ØØ$7ØØ)ô	"ÑˆA�ûð
	ús1   ®AD Â$AE Ä	E	Ä(EÅE	Å	FÅ(FÆFr4   c                 ó&  — | j                  d«      }| j                  d«      }|j                  }|j                  }t        |¬«      r|�||z  }n|| d   xs dz  }| j                  d«      }t        |¬«      r|�	||z  }||fS || d   xs dz  }||fS )NÚ&input_cost_per_token_above_128k_tokensÚ'output_cost_per_token_above_128k_tokensr)   Úinput_cost_per_tokeng        Úoutput_cost_per_token)ÚgetÚprompt_tokensr3   r   )r4   r!   r;   r<   r@   r3   r5   r8   s           r   Ú_handle_128k_pricingrA   ²   sÅ   € ð
 5?·N±NÐCkÓ4lÐ*Ø.8¯n©nÐ=fÓ.gÐ+à ×.Ñ.€MØ$×6Ñ6Ðä˜]Õ+Ð0VÐ0bØ#Ð&LÑL‰à# zÐ2HÑ'IÒ'PÈSÑQˆð /9¯n©nÐ=fÓ.gÐ+ÜÐ.Õ/Ð4[Ð4gØ+Ð.UÑUˆð ˜Ð'Ð'ð ,¨zÐ:QÑ/RÒ/YÐVYÑZˆà˜Ð'Ð'r    c                 óè   — t        j                  | |¬«      }|j                  d«      }|j                  d«      }|€|�&t        ||¬«      \  }}	t	        ||«      }
||
z  |	|
z  fS t        | ||||¬«      S )aB  
    Calculates the cost per token for a given model, prompt tokens, and completion tokens.

    Input:
        - model: str, the model name without provider prefix
        - custom_llm_provider: str, either "vertex_ai-*" or "gemini"
        - prompt_tokens: float, the number of input tokens
        - completion_tokens: float, the number of output tokens
        - service_tier: optional tier derived from Gemini trafficType
          ("priority" for ON_DEMAND_PRIORITY, "flex" for FLEX/batch).
        - vertex_location: the Vertex AI location serving the request; non-global
          locations apply the model's regional-endpoint uplift multiplier

    Returns:
        Tuple[float, float] - prompt_cost_in_usd, completion_cost_in_usd

    Raises:
        Exception if model requires >128k pricing, but model cost not mapped
    r'   r;   r<   )r4   r!   )r   r   r!   r$   r%   )r/   r0   r?   rA   r   r   )r   r   r!   r$   r%   r4   r;   r<   Úprompt_cost_128kÚcompletion_cost_128kr9   s              r   r   r   Ì   s�   € ô8  ×.Ñ.°UÐPcÔd€Jð 5?·N±NÐCkÓ4lÐ*Ø5?·^±^ÐDmÓ5nÐ+Ø-Ð9Ð=dÐ=pÜ1EØ!Øô2
Ñ.ÐÐ.ô  CÀ:ÈÓ_ˆØ -Ñ/Ð1EÈÑ1UÐUÐUä!ØØ/ØØ!Ø'ôð r    )NNNN)NN)Útypingr   r   r/   r   Ú.litellm.litellm_core_utils.llm_cost_calc.utilsr   r   r   Úlitellm.types.utilsr	   r
   r   Ú__annotations__Ústrr   ÚfloatÚtupler   rA   r   r   r    r   ú<module>rL      s~  ð÷ "Ð !ã Ý "÷ñ ÷
 1ððò )UÐ  Ó Tð Øð àð ð Ð0Ñ1°CÑ7ð ð Ð3Ñ4ó	 ðD '+Ø*.Ø#Ø"&ñrHØðrHàðrHð ðrHð ˜t‘|ð	rHð
 ! 4™<ðrHð ˜‘*ðrHð ˜4‘ZðrHð ˆ5�%ˆ<ÑórHðj(Øð(àð(ð ˆ5�%ˆ<Ñó(ð<  $Ø"&ñ/Øð/àð/ð ð/ð ˜‘*ð	/ð
 ˜4‘Zð/ð ˆ5�%ˆ<Ñô/r    